Reputation: 770
I am developing a Chrome extension which will load content script according to the following manifest:
"content_scripts" : [
{
"matches" : [ "<all_urls>" ],
"js" : [ "scripts/namespace/namespace.js",
"scripts/log/Logger.js"]
"run_at" : "document_start",
"all_frames" : true
}
]
There is a mockup site whose HTML is:
<html>
<head>
<script language=javascript>
var test;
function makewindow() {
test=window.open('mywin');
test.window.document.write("<html><body><A onclick=window.close(); href= > click Me to Close</A>");
test.window.document.write(" ---- </body></html>");
}
</script>
</head>
<body>
<a href="" onclick="makewindow();return false;" >Click me to launch the external Window</a>
</body>
</html>
If I click the A link and it will run makewindow
function and pops up a new window.
The URL of new window is about:blank
, and content script is not loaded in this new window.
How to load content script in this new window?
Upvotes: 5
Views: 5059
Reputation: 93573
Update: As of Chrome 37 (August 26, 2014), you can set the match_about_blank
flagDoc to true
to fire for about:blank
pages.
See alib_15's answer below.
For Chrome prior to version 37:
You cannot load a Chrome content script (or userscript) on about:blank
pages.
This is because about:
is not one of the "permitted schemes". From chrome extensions Match Patterns:
A match pattern is essentially a URL that begins with a permitted scheme (
http
,https
,file
,ftp
, orchrome-extension
)...
In this case, you might be better off hijacking makewindow()
.
Upvotes: 7
Reputation: 286
In the manifest file, add a line:
"content_scripts" : [
{
"matches" : [ "<all_urls>" ],
"match_about_blank" : true,
"js" : [ "scripts/namespace/namespace.js",
"scripts/log/Logger.js"]
"run_at" : "document_start",
"all_frames" : true
}
]
Upvotes: 6