mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Move onMessage listener outside start function
This commit is contained in:
parent
90016b2aff
commit
8fb9e0f6cc
1 changed files with 13 additions and 14 deletions
|
@ -395,20 +395,6 @@ async function start(el, icon, placeholder) {
|
||||||
// Skip following code if `el` provide, which mean this function run in webpage.
|
// Skip following code if `el` provide, which mean this function run in webpage.
|
||||||
if (el) return;
|
if (el) return;
|
||||||
|
|
||||||
// DO NOT USE ASYNC CALLBACK HERE, SEE THIS ISSUE:
|
|
||||||
// https://github.com/mozilla/webextension-polyfill/issues/130#issuecomment-918076049
|
|
||||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
||||||
switch (message.action) {
|
|
||||||
case "open-url": {
|
|
||||||
if (message.url) {
|
|
||||||
Omnibox.navigateToUrl(message.url);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
chrome.storage.onChanged.addListener(changes => {
|
chrome.storage.onChanged.addListener(changes => {
|
||||||
for (let [key, { oldValue, newValue }] of Object.entries(changes)) {
|
for (let [key, { oldValue, newValue }] of Object.entries(changes)) {
|
||||||
console.log('storage key updated:', key);
|
console.log('storage key updated:', key);
|
||||||
|
@ -534,5 +520,18 @@ chrome.runtime.onInstalled.addListener(async ({ previousVersion, reason }) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// DO NOT USE ASYNC CALLBACK HERE, SEE THIS ISSUE:
|
||||||
|
// https://github.com/mozilla/webextension-polyfill/issues/130#issuecomment-918076049
|
||||||
|
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||||
|
switch (message.action) {
|
||||||
|
case "open-url": {
|
||||||
|
if (message.url) {
|
||||||
|
Omnibox.navigateToUrl(message.url);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
export { start };
|
export { start };
|
||||||
|
|
Loading…
Reference in a new issue