Only first content script is loading
I am trying to build my first chrome extension, I have a problem where only first content script is being loaded. This is what I have defined in manifest.json
"content_scripts": [
{
"matches": ["http://www.facebook.com/connect/login_success.html*"],
"js": ["prototype.js", "intercept.js"]
}]
}
When I see the 开发者_如何学编程scripts loaded on this page,
http://www.facebook.com/connect/login_success.html#access_token=207C2.AQA7ebNZjXPXR8qe.3600.1307120400.1-522955158%7CCqISyuCN9QDzzIeG4rYIKW4sIvI&expires_in=4297
I see only prototype.js loaded. Any idea ?
Actually, scratch all of this. I got it working now with no apparent changes on my end. When you inject a script, however, you shouldn't be able to see it in the DOM IIRC. Is it possible you just have a stray typo that's causing it to not render? You might want to test it on other pages.
Unless it was Chrome pushing some random update that fixed things (possible), I'm thinking it might just have to do with intercept.js.
I will still give Facebook a ton of credit for using a strict doctype and failing to validate with only one word, though.
Initial answer (preserved only to demonstrate my confusion)
I was able to duplicate your result with the simplest scripts possible, which I got working on other pages. The issue might have something to do with the doctype, XHTML Strict, and the fact that -- despite the page managing to contain only a single word -- it doesn't validate. I tried several methods of dealing with it:
- Change
content_scripts.run_at
to"document_end"
in manifest.json - Use
chrome.tabs.executeScript
to inject a script - Use
chrome.tabs.executeScript
to inject pure code - Use
chrome.tabs.executeScript
to inject a script with the code surrounded in CDATA tags - Use
chrome.tabs.executeScript
to inject pure code surrounded in CDATA tags
None worked.
精彩评论