9

My Chrome extension has a content script that uses the following to inject HTML into the page:

var optionsUrl = chrome.extension.getURL("src/options/options.html"); 
var content = '<a href="' + optionsUrl + '" target="_blank">Options</a>';

This produces:

 <a href="chrome-extension://gdocgfhmbfbbbmhnhmmejncjdcbjkhfc/src/options/options.html" target="_blank">Options</a>

When I click the link, it opens a new browser tab and nothing more.

If I paste the href attribute chrome-extension://gdocgfhmbfbbbmhnhmmejncjdcbjkhfc/src/options/options.html into the address bar, I see the options page for my Chrome extension displayed correctly.

  • Why doesn't the link work?
  • Is there some extra permission that I'm missing?
dvdsmpsn
  • 2,744
  • 1
  • 23
  • 40

2 Answers2

20

In the manifest file insert:

"web_accessible_resources": ["src/options/options.html"],

more info see documentation.

Skalár Wag
  • 2,069
  • 2
  • 17
  • 20
0

Updating for Manifest v3. The following worked for me:

  "web_accessible_resources": [
    {
      "resources": [ "options.html" ],
      "matches": ["<all_urls>"]
    }
  ]

Further. I trigger the options page in a content script via:

  `chrome-extension://${chrome.runtime.id}/options.html`
Peter P.
  • 2,876
  • 2
  • 20
  • 27