バックグラウンド ページでログイン コードを取得して、ブラウザの起動時に 1 回だけ実行しようとしています。しかし、ポップアップがクリックされるたびに bgpage のグローバルコードが実行されるようです。また、異なるスコープで実行されます。これを解決することは可能ですか?
// background.js
var someCustomType = new SomeCustomType();
function SomeCustomType() {
this.firstProperty;
}
function thisShouldBeCalledOnce() {
someCustomType.firstProperty = 'defined';
alert('someCustomType.firstProperty=' + someCustomType.firstProperty);
console.log('thisShouldBeCalledOnce');
}
if (true) {
// Alwase 'undefined'
alert('someCustomType.firstProperty=' + someCustomType.firstProperty);
thisShouldBeCalledOnce();
}