chrome.runtime.connectNative generates Uncaught TypeError: undefined is not a function chrome.runtime.connectNative generates Uncaught TypeError: undefined is not a function google-chrome google-chrome

chrome.runtime.connectNative generates Uncaught TypeError: undefined is not a function


connectNative() is not available in a content scripts. To connect to a local program the content script must send the data e.g. to the background script of the extension and in the background script, port = chrome.extension.connectNativecan be used.So here a solution:

contentscript.js:

....// send data to background scriptchrome.extension.sendRequest("Some Data");....

background.js:

function connect() {    // connect to local program com.a.chrome_interface    port = chrome.extension.connectNative('com.a.chrome_interface');    port.onMessage.addListener(onNativeMessage);    port.onDisconnect.addListener(onDisconnected);}chrome.extension.onRequest.addListener(function(data, sender) {    if (data.length > 0) {        connect();        sendNativeMessage(data);    }});

manifest.json as above in my question but additionaly:

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

com.a.chrome_interface.json is unchange as in the question above.