Persist browserId between page reloads.
This commit is contained in:
parent
0fc8eeae89
commit
d184fef3dd
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];
|
if(!b || !util.isBrowserValid(b) || b === browser) delete glob.__rpcBrowsers[key];
|
||||||
});
|
});
|
||||||
glob.__rpcBrowsers[id] = browser;
|
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.browsers.forEach(initBrowser);
|
||||||
mp.events.add('browserCreated', initBrowser);
|
mp.events.add('browserCreated', initBrowser);
|
||||||
@ -97,7 +104,11 @@ if(!glob[PROCESS_EVENT]){
|
|||||||
}else{
|
}else{
|
||||||
if(typeof glob[IDENTIFIER] === 'undefined'){
|
if(typeof glob[IDENTIFIER] === 'undefined'){
|
||||||
glob[IDENTIFIER] = new Promise(resolve => {
|
glob[IDENTIFIER] = new Promise(resolve => {
|
||||||
|
if (window.name) {
|
||||||
|
resolve(window.name);
|
||||||
|
} else {
|
||||||
glob[IDENTIFIER+':resolve'] = resolve;
|
glob[IDENTIFIER+':resolve'] = resolve;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user