0

I wrote a simpler chrome extension, that opens a tab when the extension icon is clicked as follows

manifest.json

{
  "name": "Express",
  "description": "Express code name",
  "version": "1.1",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  },
  "permissions": ["storage", "activeTab","scripting","tabs"],
  "host_permissions":["http://*/*", "https://*/*"],
  "action": {   
    "default_title": "Express"
  }
}

background.js

  chrome.action.onClicked.addListener(async function (e) {
    var tab = await chrome.tabs.create({
      url: "https://www.google.com/",
    });
    chrome.scripting.executeScript({
      target: { tabId: tab.id },
      files:['content.js']
    });
  });

content.js

console.log('hello world');

but when I click on the extension icon, it shows this error message in the console

Uncaught (in promise) Error: Cannot access contents of url "". Extension manifest must request permission to access this host.

What I am doing wrong in it?

Abdul Qadir Memon
  • 882
  • 1
  • 11
  • 25
  • It's a bug in Chrome so you'll need to [wait for the URL to be set](https://stackoverflow.com/a/68611306/) first. – wOxxOm Oct 09 '21 at 05:30

0 Answers0