How can I run a Chrome extension in NW.js?
Asked Answered
C

1

7

This question is pretty short and self explanatory. I'm wondering how I can run my Chrome extension in NW.js.

I know you can run an app in NW.js and I think you can run extensions as well?

I can't find much on the topic. Back in 2013 the way to do it seemed to be:

nw [path to manifest.json] --load-extension

Any ideas are appreciated!

Carvey answered 5/9, 2016 at 17:42 Comment(8)
It seems like perhaps my extension runs, but it runs from a hotkey combination when I run it in Chrome. How do I emulate that functionality in NW.js? (assuming it is really running properly in the background)Carvey
Why? Extensions are meant to affect browser behavior.Grevera
Because my extension is built to behave much more like an app like Join from joaoapps, but I knew apps were going to be discontinued so I began my work this way. Now I'm wondering if Electron or NW.js would have been a better way to approach the issue, but I have a good deal of code down.Carvey
docs.nwjs.io/en/latest/References/Chrome%20Extension%20APIsBanebrudge
Thank you, but that has no useful information for resolving my issue.Carvey
Just a guess, try docs.nwjs.io/en/latest/References/ShortcutLolalolande
@Carvey did you install the extension properly finally?Jiujitsu
@RezaAmya, nope. Sorry. I eventually just ported my work by hand to Electron.Carvey
M
3

Yes you can.

First off, download the extension you want. For this example I'll be using this debugging tool, which adds an additional tab in the dev tools window.

  • Inside your NW.js package.json file, ensure you have an entry called chromium-args.
  • Ensure its value contains --enable-extensions --load-extension=relative_path_to_extension_manifest.

My package.json looks like this:

enter image description here


After restarting the application, the extension shows up as expected:

enter image description here

Something I'll add is that the full Chrome API might not be available to you. I couldn't find info about what NW.js supports, but Electron definitely does not support the entire API, so this might have similar restrictions.

I also noticed you mention in the comments that you need to assign a hotkey of sorts. I'd need to know what you were trying to do, but essentially you have the option of either using a browser mechanism such as addEventListener('keydown', myHandler) or using the NW.js API depending on your exact needs.

Morocco answered 26/7, 2022 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.