w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Creating a single process in C# to receive multiple Chrome Native Messages

Using chrome.runtime.connectNative, you can create a long running native instance. Then you need to keep that javascript reference alive in a background script so you can reuse it.


"background": {"scripts": ["background.js"]},


var nativePort = null;
function getNativePort(){
  if (nativePort == null)
    nativePort = chrome.runtime.connectNative("...");

If you want to send messages from a content script, you'll have to forward it to your background script first.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.