9

I'm writing a small chrome extension for personal use and I would like to run an executable via the context menu and pass certain information as arguments to said executable.

What the simplest and/or cleanest way to achieve this? To me it seems that it is impossible due to chrome's sandboxing.

watain
  • 4,838
  • 4
  • 34
  • 35

1 Answers1

11

This can be accomplished via NPAPI Plugins.

Code running in an NPAPI plugin has the full permissions of the current user and is not sandboxed or shielded from malicious input by Google Chrome in any way. You should be especially cautious when processing input from untrusted sources, such as when working with content scripts or XMLHttpRequest.

However, I should also include their warning.

Warning

NPAPI is being phased out. Consider using alternatives.

NPAPI is a really big hammer that should only be used when no other approach will work.

via Start an external application from a Google Chrome Extension?

Alternatives to NPAPI

  1. There are several alternatives to NPAPI. In cases where standard web technologies are not yet sufficient, developers and administrators can use NaCl, Apps, Native Messaging API, and Legacy Browser Support to transition from NPAPI. Moving forward, our goal is to evolve the standards-based web platform to cover the use cases once served by NPAPI.

    via http://blog.chromium.org/2013/09/saying-goodbye-to-our-old-friend-npapi.html

  2. Another way, suggested here, is with Java.

    Java applets: http://docs.oracle.com/javase/tutorial/deployment/applet/

    Implementing Policy: http://docs.oracle.com/javase/tutorial/security/userperm/policy.html

  3. Use sendNativeMessage:

    There is chrome.runtime.sendNativeMessage which can be used to send a message to a native application and chrome.runtime.connectNative which allows for a more persistent connection.

    So, you can't directly execute a command, but you can have a native app do it for you.

    You can find more info on Native Messaging in the docs.

    via https://stackoverflow.com/a/19917672/1085891

Community
  • 1
  • 1
JSuar
  • 21,056
  • 4
  • 39
  • 83
  • So since NPAPI is being phased out, which one of the alternatives should I use? I just want to execute an external program/script, so Apps, Native Messaging API and Legacy Browser Support don't seem to be an option. – watain Jan 11 '14 at 13:14
  • I'm gonna test example given in their page via "Native Messaging" https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/nativeMessaging – Deele Feb 24 '15 at 15:50
  • Native Messaging seems like the key to getting ZPL and Generic Text-Only printing to work at full speed without prerendering. Albeit, in a chrome only way. – Ray Foss Feb 04 '16 at 16:00
  • @JSuar, Isn't **PPAPI** the replacement for NPAPI? – Pacerier Dec 16 '16 at 11:40
  • @Pacerier, yes, I think you're right. I don't know enough and couldn't locate info on PPAPI capabilities as it relates to the original question. – JSuar Dec 18 '16 at 14:52