Unable to read property "onPageChanged" from undefined

sample extension background.js code

chrome.runtime.onInstalled.addListener(function() { chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { chrome.declarativeContent.onPageChanged.addRules([{ conditions: [ // When a page contains a <video> tag... new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostEquals: 'www.youtube.com'} }) ], // ... show the page action. actions: [new chrome.declarativeContent.ShowPageAction() ] }]); }); 

});

and I got I can not read the "onPageChanged" property from undefined in the console. No problem running the code, why is this happening?

+7
javascript google-chrome google-chrome-extension
source share
1 answer

Make sure you add the declarativeContent permission to the manifest.json file.
This will give your extension access to the chrome.declarativeContent API and should solve your problem.

+11
source share

All Articles