Merge pull request #5 from Yiin/patch-1

Persist browserId between page reloads.
This commit is contained in:
Micah Allen 2019-03-20 22:57:49 -04:00 committed by GitHub
commit 1dc43b87be
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];
});
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;
}
});
}
}