PlasmoHQ / docs

📘 Documentation site
https://docs.plasmo.com
12 stars 50 forks source link

There is a problem with “Background Service Worker + Shortcut Commands” #51

Closed shamimurrahman19 closed 1 year ago

shamimurrahman19 commented 1 year ago

There is an issue.

Chrome extension shortcut commands are not working in build mode. Shortcut commands work in dev mode. but after building they don't work. add the following codes and run "pnpm build".

//background.ts code
export {}
chrome.commands.onCommand.addListener(function(command) {
    if (command === "shortcutPressed") {
        console.log("shortcut command was pressed");
    }
  });
console.log("background.ts is active");

//package.json manifest code
  "manifest": {
    "host_permissions": [
      "https://*/*"
    ],
    "commands": {
      "shortcutPressed": {
        "suggested_key": {
          "default": "Alt+W"
        },
        "description": "Open the extension main popup"
      }
    }
  }
louisgv commented 1 year ago

@shamimurrahman19 can you send the generated manifest.json for prod version?

shamimurrahman19 commented 1 year ago

Here it is:

On Sat, 6 May 2023 at 18:47, L @.***> wrote:

@shamimurrahman19 https://github.com/shamimurrahman19 can you send the generated manifest.json for prod version?

— Reply to this email directly, view it on GitHub https://github.com/PlasmoHQ/docs/issues/51#issuecomment-1537135147, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALB4EDRKR6USG6ZSKADTFK3XEZB7RANCNFSM6AAAAAAXYCGX6A . You are receiving this because you were mentioned.Message ID: @.***>

-- SOA

shamimurrahman19 commented 1 year ago
{
  "icons": {
    "16": "icon16.plasmo.754a7afc.png",
    "32": "icon32.plasmo.1b596b7f.png",
    "48": "icon48.plasmo.9c45e82d.png",
    "64": "icon64.plasmo.696cf0ec.png",
    "128": "icon128.plasmo.f5004619.png"
  },
  "manifest_version": 3,
  "action": {
    "default_icon": {
      "16": "icon16.plasmo.754a7afc.png",
      "32": "icon32.plasmo.1b596b7f.png",
      "48": "icon48.plasmo.9c45e82d.png",
      "64": "icon64.plasmo.696cf0ec.png",
      "128": "icon128.plasmo.f5004619.png"
    },
    "default_popup": "popup.html"
  },
  "version": "0.0.3",
  "author": "shamimurrahman19",
  "name": "Retextpro",
  "description": "retextpro description",
  "background": {
    "service_worker": "background.b78a8f7f.js"
  },
  "host_permissions": [
    "https://*/*"
  ],
  "commands": {
    "shortcutPressed": {
      "suggested_key": {
        "default": "Alt+W"
      },
      "description": "Open the extension main popup"
    }
  }
}
louisgv commented 1 year ago

@shamimurrahman19 Looks correct, so I'm not entirely sure. I have extension that uses this feature as well, and it works. Which version of the framework are you using?

louisgv commented 1 year ago

@shamimurrahman19 I found the issue - it's on chrome's shortcut registration. Basically, you must remove your dev extension so that it will de-register the command. Otherwise, even if you disable the dev extension, it will still stick to the dev's binding instead of the prod.

shamimurrahman19 commented 1 year ago

Thank you.