0

This helped me to understand how to implement native host for Chrome, however, the whole reason I'm going this way is that I can have one shared state where I can store data and send/request back and forth between host and extension running in multiple Chrome Windows.

So naturally comes the question of read/write locks and syncing request. The example above uses stdin in a way I'm not familiar with. How would I ensure data integrity and prevent possible case when another request is send in-between while first one is being processed? I can implement R/W lock ad mutexes on the native part, but the communication part with Chrome is what confuses me. Because extension instances can run on a completely separate Chrome windows instances (and potentially one vanilla Chromium), I can't implement any kind of syncing on this side.

Kirikan
  • 119
  • 6
  • There's no need for that because another request cannot be sent in between as each extension launches exactly one native host and the messages are sent sequentially. – wOxxOm Jul 05 '23 at 19:52
  • @wOxxOm what do you mean by `as each extension launches exactly one native host `. Are you saying I can't have it actively running as long as any browser instance is alive? That was kind of the whole point. – Kirikan Jul 05 '23 at 20:07
  • Multiple browser windows doesn't mean multiple extensions. Only multiple browser windows with different profiles would run multiple instances of an extension, each one launching its own instance of the native host. If you want to have a single native host you can use a HTTP port for communication on localhost via `fetch` in the extension. – wOxxOm Jul 06 '23 at 05:30
  • There is no point using HTTP because it would mean I have to deserialize JSON to object, which I can do faster with `localSotrage`. I'm actually more interested in your first statement. I run 2 different browser window, same profile but on is ran with `---proxy` arg and I cannot get data from persist. offscreen script via messaging in new instance. – Kirikan Jul 06 '23 at 09:55
  • 1) JSON is not a problem because nativeMessaging does it internally anyway. 2) I have no idea how *exactly* you try to persist the data as I don't see the code. You can see what happens and how your host is launched by using a task manager in the OS. – wOxxOm Jul 06 '23 at 21:22
  • I think I understand why, when you add `--proxy-server="socks5://127.0.0.1:1081` command line arg it launches some ephemeral temporal profile loosely based off you main and so everything is separate. As for the native host, I see no point using it if I can't have it running persistent whle chrome is active. Launching binary every time or using HTTP server is way worse and clunkier than just `localStorage`. I appreciate the answers. – Kirikan Jul 07 '23 at 19:48

0 Answers0