-1

I'm following this tutorial about creating a popup demo Chrome extension. I literally copied all the codes in correct files inside correct paths but the code in background.js doesn't seem to work. I got the HTML mini page when I clicked on the extension icon but there was no popup for alert. I used Inspect for the service worker (background.js) and saw that it was active so I'm really confused how it could not work. FYI, I'm using the latest Chrome version and when my friend tested the same code it didn't work as well.

Edit: I just double checked the error console. Now it gives me these errors: that I really don't know how to handle (browser undefined, cannot access chrome URL, etc) errors

  • can you share your popup.html file – user11877521 Oct 22 '22 at 04:52
  • Is it "Injecting a content script on click" ? It doesn't work on some pages. This page should work. – Norio Yamamoto Oct 22 '22 at 05:02
  • @NorioYamamoto which page are you referring to? – Cassie Nguyen Oct 22 '22 at 06:34
  • @Cassie Nguyen, Exactly [this page](https://stackoverflow.com/questions/74161135/service-worker-doesnt-seem-to-work-for-chrome-extension) . The extension's admin page gives an error. – Norio Yamamoto Oct 22 '22 at 06:43
  • @Cassie Nguyen, It's strange. The same tutorial as yours works fine in my chrome. I have one request. The HTML mini page will not be displayed in this tutorial. Can you post a capture of it? – Norio Yamamoto Oct 22 '22 at 07:16
  • Does your code contain any referenes to `browser`? And which lines contain `.onClicked`? – Thomas Mueller Oct 22 '22 at 11:19
  • @ThomasMueller you can check the image. It's on line 2. – Cassie Nguyen Oct 22 '22 at 14:23
  • @NorioYamamoto i was mistaken with the other tutorial about the HTML thing. But the code still didn't work for me. Now it gave me new errors (just added new edits) – Cassie Nguyen Oct 22 '22 at 14:24
  • The error message means that `chrome.action` is undefined. `manifest.json` must be missing [the `action` key](https://developer.chrome.com/docs/extensions/reference/action/#manifest) – Thomas Mueller Oct 22 '22 at 14:43
  • @Cassie Nguyen, Are the files that make up your extension the same as this? [Injecting-a-content-script-on-click](https://github.com/NorioYamamoto/Injecting-a-content-script-on-click) – Norio Yamamoto Oct 22 '22 at 22:52

1 Answers1

1

I think you removed the action key from the manifest.json in the tutorial. For example:

{
  "name": "Action script injection demo",
  "version": "1.0",
  "manifest_version": 3,
  "permissions": ["activeTab", "scripting"],
  "background": {
    "service_worker": "background.js"
  }
}

And I think the following error occurs when loading the extension.
enter image description here enter image description here

Norio Yamamoto
  • 1,495
  • 2
  • 3
  • 10