前提・実現したいこと
chrome extensionを作っています。
background.jsにsendMessageしてresponseを受け取り、responseを使ってその後の処理を行いたいのに、responseを待たずに次の処理に進んでしまい、困っています。
以下のコードではconsole.logの出力が必ず
実行順2 結果false
実行順1
となります。
実行順1
実行順2 結果true(false)
とするにはどうすればよろしいでしょうか。
該当のソースコード
javascript
1var IsVisited;//boolean 2chrome.runtime.sendMessage({ url: url }, response => { 3 IsVisited = response.visited; 4 console.log('実行順1'); 5}); 6 7if (IsVisited){ 8 console.log('実行順2 結果true'); 9}else{ 10 console.log('実行順2 結果false'); 11};
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/16 20:25
2019/08/16 20:26 編集