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!

Slbox
  • 10,957
  • 15
  • 54
  • 106
  • 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) – Slbox Sep 05 '16 at 17:53
  • Why? Extensions are meant to affect browser behavior. – Daniel Herr Sep 05 '16 at 21:31
  • 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. – Slbox Sep 05 '16 at 22:11
  • 1
    http://docs.nwjs.io/en/latest/References/Chrome%20Extension%20APIs/ – Haibara Ai Sep 06 '16 at 00:37
  • 1
    Thank you, but that has no useful information for resolving my issue. – Slbox Sep 06 '16 at 13:43
  • Just a guess, try http://docs.nwjs.io/en/latest/References/Shortcut/ – wOxxOm Sep 09 '16 at 09:20
  • @Slbox did you install the extension properly finally? – Reza Amya Jan 27 '19 at 17:03
  • @RezaAmya, nope. Sorry. I eventually just ported my work by hand to Electron. – Slbox Jan 27 '19 at 17:11

1 Answers1

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.

aggregate1166877
  • 2,196
  • 23
  • 38