Merge pull request #5 from Yiin/patch-1
Persist browserId between page reloads.
This commit is contained in:
commit
1dc43b87be
15
src/index.ts
15
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 => {
|
||||||
glob[IDENTIFIER+':resolve'] = resolve;
|
if (window.name) {
|
||||||
|
resolve(window.name);
|
||||||
|
} else {
|
||||||
|
glob[IDENTIFIER+':resolve'] = resolve;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user