Chrome extension show page action example manifest v3

Viewed 1042

I'm trying to reproduce this example with the manifest v3. But my action is always active - I expext it to be disabled on all pages without 'g' in a URL.

Thanks in advance!

manifest.json

{
   "name":"Example",
   "description":"description",
   "version":"0.1",
   "manifest_version":3,
   "background":{
      "service_worker":"background.js"
   },
   "permissions":[
      "declarativeContent"
   ],
   "action":{
      "default_icon":{
         "16":"/images/get_started16.png",
         "32":"/images/get_started32.png",
         "48":"/images/get_started48.png",
         "128":"/images/get_started128.png"
      },
      "default_title":"press here to open"
   },
   "icons":{
      "16":"/images/get_started16.png",
      "32":"/images/get_started32.png",
      "48":"/images/get_started48.png",
      "128":"/images/get_started128.png"
   }
}

background.js

chrome.runtime.onInstalled.addListener(() => {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page's URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: 'g' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ], function callback(details) {
      console.log("chrome.declarativeContent.onPageChanged.addRules callback");
      console.log(details);
    });
  });
});
1 Answers
Related