2016-12-23 4 views
0

일치에 JS를로드하지 content_script, 아무것도 내가 확장을 만들려고하고, 지금 거기에 대해 해요 ...Google 크롬에도 스택 오버 플로우의 주제를 많이 검색 한 후 URL

을이 오류를 해결하기 위해 저를 도왔 안타깝게도 콘솔에 'Hello, world!'가 기록되지 않습니다. content_scripts 파일에서.

manifest.json을

{ 
    "manifest_version": 2, 

    "name": "Example", 
    "shortname": "exmpl", 
    "description": "__MSG_appDesc__", 
    "version": "0.0.1", 
    "default_locale": "en", 
    "author": "Mateus Akino", 
    "icons": { 
     "16": "i16x.png", 
     "48": "i48x.png", 
     "128": "i128x.png" 
    }, 
    "homepage_url": "http://example.com/", 
    "browser_action": { 
     "default_icon": "i32x.png", 
     "default_popup": "popup.html" 
    }, 
    "update_url": "http://example.com/update.xml", 
    "chrome_url_overrides": { 
     "newtab": "newtab.html" 
    }, 
    "content_scripts": [{ 
     "matches": ["*://*.youtube.com/*"], 
     "js": ["execute.js"], 
     "run_at": "document_end" 
    }], 
    "background": { 
     "scripts": ["background.js"] 
    }, 
    "permissions": [ 
    "activeTab", "tabs", "i18n", "management", "webNavigation", "<all_urls>" 
    ] 
} 

execute.js

console.log("Hello, world!"); 

background.js

chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) { 
    chrome.tabs.executeScript(null, { 
     file: "execute.js" 
    }); 
}); 
+1

배경 페이지가 전혀 필요 없기 때문에 ['spfdone' 이벤트] (http://stackoverflow.com/a/32277150/)가 더 나은 해결책이라고 생각합니다. – wOxxOm

+0

테스트 할 페이지가 있으며 'chrome.webNavigation.onHistoryStateUpdated.addListener'가 호출되도록 할 수 있습니까? –

+0

@HaibaraAi 'console.log ("Test"); "를 추가하고 호출하지 않는 것 같습니다. – Mateus

답변

1

나는 문제를 해결, 그래서 ' 다른 사람이이 문제가있는 경우 여기에 게시하고 있습니다 ...

좋아요, 코드는 괜찮은 것처럼 보이지만,이 확장을로드하는 방식에 문제가 있습니다 ... '압축 해제 된 내선 '을로드하는 대신 내 manifest.json을 사용 중지 및 사용 설정하여 업데이트하지 않았습니다 (새로 고침 확장 프로그램 now).

그래서 확장을 제거하고 다시로드 했으므로 현재 정상적으로 작동합니다. 고마워요!

+0

언팩 된 확장의 매니페스트는 * 마우스를 사용하여 * Reload (Ctrl-R)을 클릭하십시오. – wOxxOm