Persist browserId between page reloads.

This commit is contained in:
Yiin 2019-03-17 20:54:45 +02:00 committed by GitHub
parent 0fc8eeae89
commit d184fef3dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
}); });
} }
} }