I reworked the "Clip to DEVONthink" to use in Opera 15+. The problem I'm left with is that the extension only works after a browser restart.
Update 1: Tested on Mac OS X 10.9.2 with Opera 21.0.1432.67, Opera Next 22.0.1471.40 and Google Chrome 35.0.1916.114. They all behave the same.
Update 2: Opera's own example for message passing got the same behavior. I'm left with the question if that's the expected behavior.
There's a background script defined in manifest.json:
"background": {
"scripts": [ "main.js" ]
},
and a content script:
"content_scripts": [ {
"js": [ "add_listener.js" ],
"matches": [ "http://*/*", "https://*/*" ],
}],
... and in main.js in chrome.browserAction.onClicked.addListener a message is send to the content script to request page title & content, etc.
chrome.browserAction.onClicked.addListener(
function (tab) {
chrome.tabs.sendMessage(tab.id, {line: 'getdevonthinkurl' });
}
);
... and the content script sends a message back:
chrome.runtime.onMessage.addListener(
function (request, sender){
if (request.line=='getdevonthinkurl'){
chrome.runtime.sendMessage({devonthinkurl:getDEVONthinkURL()});
}
}
);
... and that message is received by the main.js background script:
chrome.runtime.onMessage.addListener(
function (request, sender) {
if (request.devonthinkurl){
chrome.tabs.update(sender.tab.id, {"url": request.devonthinkurl});
}
}
);
As mentioned above it works perfect after a browser restart but it don't understand why it won't work without.
Does anyone have got an idea (I may add I'm not strong at programming and there's maybe an fundamental flaw in the design)?