Enhance: faster msg.sendBg (#774)
This commit is contained in:
parent
0e9d5ce08c
commit
a7445011a9
16
js/msg.js
16
js/msg.js
|
@ -41,11 +41,19 @@ const msg = (() => {
|
||||||
if (isBg) {
|
if (isBg) {
|
||||||
return Promise.resolve(window);
|
return Promise.resolve(window);
|
||||||
}
|
}
|
||||||
if (!chrome.runtime.getBackgroundPage) {
|
// try using extension.getBackgroundPage because runtime.getBackgroundPage is too slow
|
||||||
return Promise.resolve();
|
// https://github.com/openstyles/stylus/issues/771
|
||||||
|
if (chrome.extension.getBackgroundPage) {
|
||||||
|
const bg = chrome.extension.getBackgroundPage();
|
||||||
|
if (bg && bg.document && bg.document.readyState !== 'loading') {
|
||||||
|
return Promise.resolve(bg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return promisify(chrome.runtime.getBackgroundPage.bind(chrome.runtime))()
|
if (chrome.runtime.getBackgroundPage) {
|
||||||
.catch(() => null);
|
return promisify(chrome.runtime.getBackgroundPage.bind(chrome.runtime))()
|
||||||
|
.catch(() => null);
|
||||||
|
}
|
||||||
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send(data, target = 'extension') {
|
function send(data, target = 'extension') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user