Is it possible to handle messages from background in two or more scripts injected in one web-page?
I add
chrome.runtime.onMessage.addListener
to more scripts.
I have more commands. Using ctrl+shift+N for inspector and ctrl+shif+E for extractor. Both have different scripts. So when I hit hotkey I send message which should be proccessed in the script. But because I have more features, so I have more scripts like this. Is it possible that if I capture the message in one script it will not go to the second script? Maybe the script which is connected later overwrites the already loaded listener?
How to solve this? I think like the features are affected each other so no one works correctly.
Should I add named functions instead anonymous?
One more question:
Do all features (content scripts) share same scope or they have different scope each?
The inspector and extractor have similar namespace:
var mynamespace = {
isHidden: false,
isAppend: false,
elements: { length: 0, collection:[] },
inspector: { data: {}},
tabOpened: false,
tabID: null,
def_obj: { zindex: null, size: null, font: null, weight: null, stylesheet: null, styles: null}
};
var mynamespace = {
elements: { length: 0, collection:[] },
inspector: { data: {}},
tabOpened: false,
tabID: null,
def_obj: { zindex: null, size: null, font: null, weight: null, stylesheet: null, styles: null}
};
So are they overwritten and in a conflict?
Do I need to retype them like that?
var mynamespace.inspector = {
isHidden: false,
isAppend: false,
elements: { length: 0, collection:[] },
inspector: { data: {}},
tabOpened: false,
tabID: null,
def_obj: { zindex: null, size: null, font: null, weight: null, stylesheet: null, styles: null}
};
var mynamespace.extractor = {
elements: { length: 0, collection:[] },
inspector: { data: {}},
tabOpened: false,
tabID: null,
def_obj: { zindex: null, size: null, font: null, weight: null, stylesheet: null, styles: null}
};
???