Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read property 'onPageChanged' of 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 Cannot read property 'onPageChanged' of undefined in console. No problem running the code, why is that happening?

like image 546
user3522749 Avatar asked Aug 20 '14 16:08

user3522749


1 Answers

Check that you have added the declarativeContent permission to your manifest.json file.
This will give your extension access to the chrome.declarativeContent API and should resolve your problem.

like image 155
rd3n Avatar answered Sep 27 '22 21:09

rd3n