Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 627
Slbox Avatar asked Nov 20 '22 19:11

Slbox


1 Answers

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.

like image 68
aggregate1166877 Avatar answered Nov 22 '22 09:11

aggregate1166877