I have a manifest.json file that looks like this:
{
"name": "Zend Debugger Extension",
"version": "0.1",
"background_page": "background.html",
"permissions": [
"cookies", "tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "Launch Zend Debugger",
"default_icon": "icon.png",
"popup": "popup.html"
}
}
Here's my background.html:
<html>
<script>
function testRequest() {
console.log("test Request received");
}
</script>
</html>
And my popup.html:
<script>
function debug(target) {
if (target.id == 'thisPage') {
console.log('sending request');
chrome.extension.getBackgroundPage().testRequest();
}
}
</script>
<div onclick="debug(this)" id="thisPage">Current Page</div>
However, the background.html page doesn't seem to be accessible. I'm getting this error:
Uncaught TypeError: Cannot call method 'testRequest' of null
When I inspect chrome.extension.getBackgroundPage()
I get a null value. I'm thinking I have made a mistake in my manifest file, but I can't see what I've done wrong.
Thanks.
Here's another answer with more options:
chrome.extension.getBackgroundPage() returns null after awhile
According to the referenced page (Difference between Event and Background Page) there is a better option to get the background while still using Event Page :
If your extension uses, extension.getBackgroundPage, switch to runtime.getBackgroundPage instead. The newer method is asynchronous so that it can start the event page if necessary before returning it.
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