I want to create a new tab using Chrome Extension and when tab is loaded to show tab.id. Page is loaded but callback function is not worked (alert with tab.id is now showed).
The background.js file:
chrome.tabs.create({'url': 'http://www.google.com'}, function(tab){ alert(tab.id) })
The manifest.json file:
{
"name": "Test",
"version": "1.0",
"description": "Test plugin",
"browser_action": {
"default_popup": "popup.html",
"default_icon":"icon.png"
},
"background": {
"scripts": ["background.js"]
},
"manifest_version":2,
"permissions": [
"tabs",
"http://*.facebook.com/*",
"http://*.google.com/*",
"storage"
]
}
The popup.html file:
<html>
<head>
<title>Test tabs</title>
</head>
<body>
<script type="text/javascript" src=/background.js"></script>
</body>
</html>
What can be a problem?
Your code must be located in background pages.
This is in the manifest.json file:
"background" : {"scripts" : ["background_script.js"] }
or
"background" : {"page" : "background_page.html" }
You need to use absolute path when you referring to the file inside background page:
<script type="text/javascript" src="/background.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With