Access Local Files using a Google Chrome Extension

后端 未结 3 1676
有刺的猬
有刺的猬 2020-12-05 02:50

I have asked a similar question to this previously

Communicate with Cash Drawer from Website

However the question was very vague and I now know what I requir

相关标签:
3条回答
  • 2020-12-05 03:26

    It's not allowed for security reasons. If running a .bat file was allowed, it would allow malicious commands to be run on the computer.

    0 讨论(0)
  • 2020-12-05 03:30

    You are going to need to write a Chrome extension that exposes an API to your website. This is the easy part. You inject a content script to your website, and then use chrome.extension.sendMessage to communicate back to your extension.

    The hard part is to actually open the bat file from your extension. With NPAPI, this would have been easy, since you could just write a C++ plugin that calls CreateProcess or something. Contrary to what you said, it's a pretty good solution. But unfortunately, NPAPI isn't an option, since it's being deprecated.

    So what you should do is to use Native Messaging. Basically, it's a Chrome API that allows extensions to exchange messages with native applications using standard input and output streams.

    Read more about it here: https://developer.chrome.com/extensions/messaging#native-messaging-host

    0 讨论(0)
  • 2020-12-05 03:36
    • If you have access to the machines where your product is deployed, you can use NaCL and start chrome with --no-sandbox command-line flag and use the following environment variable:

      set NACL_DANGEROUS_ENABLE_FILE_ACCESS=1

      More info on this blog

    • The other option is NPAPI.

    0 讨论(0)
提交回复
热议问题