Merge pull request #5 from Yiin/patch-1
Persist browserId between page reloads.
This commit is contained in:
commit
1dc43b87be
13
src/index.ts
13
src/index.ts
@ -78,7 +78,14 @@ if(!glob[PROCESS_EVENT]){
|
||||
if(!b || !util.isBrowserValid(b) || b === browser) delete glob.__rpcBrowsers[key];
|
||||
});
|
||||
glob.__rpcBrowsers[id] = browser;
|
||||
browser.execute(`if(typeof window['${IDENTIFIER}'] === 'undefined'){ window['${IDENTIFIER}'] = Promise.resolve('${id}'); }else{ window['${IDENTIFIER}:resolve']('${id}'); }`);
|
||||
browser.execute(`
|
||||
window.name = '${id}';
|
||||
if (typeof window['${IDENTIFIER}'] === 'undefined') {
|
||||
window['${IDENTIFIER}'] = Promise.resolve(window.name);
|
||||
} else {
|
||||
window['${IDENTIFIER}:resolve'](window.name);
|
||||
}
|
||||
`);
|
||||
};
|
||||
mp.browsers.forEach(initBrowser);
|
||||
mp.events.add('browserCreated', initBrowser);
|
||||
@ -97,7 +104,11 @@ if(!glob[PROCESS_EVENT]){
|
||||
}else{
|
||||
if(typeof glob[IDENTIFIER] === 'undefined'){
|
||||
glob[IDENTIFIER] = new Promise(resolve => {
|
||||
if (window.name) {
|
||||
resolve(window.name);
|
||||
} else {
|
||||
glob[IDENTIFIER+':resolve'] = resolve;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user