I've been working on a Chrome extension that uses a native messaging host. In my background.js file, I have set up a listener to process all onBeforeRequest events and pass them to the native helper application. Everything works fine when a page is visited after Chrome has started, but when I open Chrome by clicking a URL, the listener does not activate.
Here's how the listener is structured in my background.js:
chrome.webRequest.onBeforeRequest.addListener(function (details) {
alert('forwarding request!');
chrome.runtime.sendNativeMessage('<extension name>', { url: details.url });
}, { urls: ['http://*', 'https://*'] }, ['blocking']);
There are certain conditions to determine if the request should be passed on or blocked in Chrome, but they're not important here. Even without the sendNativeMessage part, I can't seem to trigger an alert for the URL clicked to launch Chrome.
Any creative ideas on how to register this listener before the first request at startup is made?