クローム拡張インストール/アップデートイベントについて質問があります。バックグラウンドスクリプトのトップレベルコードにonInstalledイベントリスナーを追加すると、イベントリスナーがそのイベントを捕捉する時間枠がありますか?クロム拡張onInstalledイベント
私のデモでは、onInstalledリスナーをフックする前に実行するロジックがあると、その間にイベントが発生したように実行されないように見えるので、これを尋ねています。
誰かが、このイベントがどのように機能するか、バックグラウンドスクリプトの他のロジックのコンテキストで、私が何か有用なものを見つけることができなかったため、いくつかのドキュメントを指摘してくれます。
ありがとうございます!
更新@Noamハッカーは:により、会社の方針に私はここに任意の実際のコードを投稿することはできませんが、私は私の問題を説明するいくつかの擬似コードを持っている:
/**
* setup in which I miss onInstalled event
*/
function firstLogicThatRunsOnBackgroundLoad() {
// perform some logic
// perform some asynchronous operations via generators and promises
// which can take a while
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
// this logic never gets executed
} else if(details.reason == "update") {
// perform some logic
}
});
}
/**
* setup in which I catch onInstalled event
*/
function firstLogicThatRunsOnBackgroundLoad() {
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
// this logic executes
} else if(details.reason == "update") {
// perform some logic
}
});
// perform some logic
// perform some asynchronous operations via generators and promises
// which can take a while
}
背景スクリプトのサンプルコードはありますか? –
リスナー関数の内部にプライマリロジックを置くとどうなりますか? 'chrome.runtime.onInstalled.addListener(function(details){ //最初にやりたいロジックを実行... //インストール/更新ロジック... }' –
@NoamHackerもし私が私がリスナー関数の中で最初に実行したいロジックで、私のテストでは、バックグラウンドに他のロジックがある場合、このロジックが最初に実行されるという保証はないことが示されました。 – slickman