크롬 확장 프로그램을 만들고 있습니다. 작동 방법 :Chrome 확장 프로그램 페이지로드가 너무 느리기 때문에 setInterval 또는 setTimeout이 발생합니다.
확장 프로그램 열기 -> 현재 탭에서 새 페이지로드 ->이 페이지에서 컨텐츠 읽기 ->이 내용을 확장자 html 코드 (popup.html)에 삽입하십시오.
현재 작동 : 확장 기능 (ok) -> 현재 탭에서 새 페이지로드 (ok) ->이 페이지에서 내용 읽기 (?) ->이 내용을 확장자 html 코드 (popup.html)에 삽입하십시오. 작동 안함).
그러나 확장 프로그램을 닫고 다시 열면 작동합니다. 페이지로드가 너무 느리고 3 단계 또는 4 단계에서 시간 초과 또는 간격을 설정해야하기 때문에 이것이라고 생각합니다. setInterval 및 setTimeout 함수를 시도했지만 실패했습니다.
<!DOCTYPE html>
<html>
<head>
<meta name="myName" content="empty">
</head>
<body>
page content
</body>
</html>
popup.js :
// Inject the payload.js script into the current tab after the popout has loaded
window.addEventListener('load', function (evt) {
chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, {
file: 'payload.js'
});
chrome.tabs.update(null, {url:"https://mypage.com"});;
});
// Listen to messages from the payload.js script and write to popout.html
chrome.runtime.onMessage.addListener(function (message) {
document.getElementsByName("myName")[0].setAttribute("content", message);
});
payload.js :
// send the page title as a chrome message
chrome.runtime.sendMessage(document.getElementsByTagName("META")[0].content);
매니페스트
여기 (I 불필요한 물건을 삭제 한) 내 popup.html입니다. json :
{
"manifest_version": 2,
"name": "MyName",
"description": "empty!",
"version": "0.2",
"author": "me",
"background": {
"scripts": ["popup.js"],
"persistent": true
},
"icons": { "16": "icon_16.png",
"48": "icon_48.png",
"128": "icon_128.png" },
"permissions": [
"tabs",
"http://*/",
"https://*/"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
setInterval(function(){ code; }, 500);
을 popup.js 및/또는 payload.js에 적용하려고 시도했지만 작동하지 않습니다.
그리고 background.js에 무엇을 넣어야합니까? – mrblue