use getParentStyles in about:blank iframes

This commit is contained in:
tophf 2020-12-19 13:04:46 +03:00
parent b037713c7d
commit 913b4eb1c4

View File

@ -58,12 +58,15 @@ define(require => {
if (STYLE_VIA_API) { if (STYLE_VIA_API) {
await API.styleViaAPI({method: 'styleApply'}); await API.styleViaAPI({method: 'styleApply'});
} else { } else {
const SYM = Symbol.for('styles'); const SYM_ID = 'styles';
const SYM = Symbol.for(SYM_ID);
const styles = const styles =
window[SYM] || window[SYM] ||
chrome.app && !chrome.tabs && getStylesViaXhr() || (IS_FRAME && location.href === 'about:blank'
? getParentStyles(SYM_ID)
: chrome.app && !chrome.tabs && getStylesViaXhr()) ||
await API.styles.getSectionsByUrl(getMatchUrl(), null, true); await API.styles.getSectionsByUrl(getMatchUrl(), null, true);
delete window[SYM]; window[SYM] = styles;
if (styles.disableAll) { if (styles.disableAll) {
delete styles.disableAll; delete styles.disableAll;
styleInjector.toggle(false); styleInjector.toggle(false);
@ -72,6 +75,12 @@ define(require => {
} }
} }
function getParentStyles(id) {
try {
return parent[parent.Symbol.for(id)];
} catch (e) {}
}
function getStylesViaXhr() { function getStylesViaXhr() {
try { try {
const blobId = document.cookie.split(chrome.runtime.id + '=')[1].split(';')[0]; const blobId = document.cookie.split(chrome.runtime.id + '=')[1].split(';')[0];