I'm trying to load an HTML file from my extension's folder into a new tab. There is no URL in this tab. Why doesn't Content Script work in it?
Here is my extension code:
manifest.json
{
"manifest_version": 2,
"name": "Content Script test",
"description": "Content Script test.",
"version": "1.0",
"icons": {
"16": "icon-16.png",
"48": "icon-48.png"
},
"permissions": [
"tabs"
],
"background": {
"persistant": false,
"scripts": ["background.js"]
},
"content_scripts": [
{
//"matches": ["file:///*/inject.html"],
// Content Script works only for non-empty URL's (stackoverflow.com for example).
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"web_accessible_resources": [
"inject.js"
],
"browser_action": {
"default_icon": "icon-16.png",
"default_title": "Contents Script test"
}
}
background.js
chrome.browserAction.onClicked.addListener(function ()
{
// Address bar in new tab will be empty.
chrome.tabs.create(
{
url: chrome.extension.getURL('inject.html'),
active: true
},
function (tab)
{
chrome.tabs.sendMessage(tab.id, {});
});
});
Content Script doesn't work on empty URL but on other URL's works fine. Sending message not working in new tab with empty url.
content.js
alert('test content');
//debugger;
chrome.runtime.onMessage.addListener(function (msg, sender, sendResp)
{
alert('test msg');
});
inject.html
<html>
<head>
</head>
<body>
<p>Hello</p>
</body>
</html>