Allow apiInjectStylesheet to inject a URL

This commit is contained in:
toasted-nutbread 2020-02-16 13:13:04 -05:00
parent 1c6ed1d286
commit 2c3f510010
3 changed files with 19 additions and 10 deletions

View File

@ -499,19 +499,28 @@ class Backend {
return Promise.resolve({frameId}); return Promise.resolve({frameId});
} }
_onApiInjectStylesheet({css}, sender) { _onApiInjectStylesheet({type, value}, sender) {
if (!sender.tab) { if (!sender.tab) {
return Promise.reject(new Error('Invalid tab')); return Promise.reject(new Error('Invalid tab'));
} }
const tabId = sender.tab.id; const tabId = sender.tab.id;
const frameId = sender.frameId; const frameId = sender.frameId;
const details = { const details = (
code: css, type === 'file' ?
runAt: 'document_start', {
cssOrigin: 'user', file: value,
allFrames: false runAt: 'document_start',
}; cssOrigin: 'author',
allFrames: false
} :
{
code: value,
runAt: 'document_start',
cssOrigin: 'user',
allFrames: false
}
);
if (typeof frameId === 'number') { if (typeof frameId === 'number') {
details.frameId = frameId; details.frameId = frameId;
} }

View File

@ -167,7 +167,7 @@ class Popup {
} else { } else {
if (!css) { return; } if (!css) { return; }
try { try {
await apiInjectStylesheet(css); await apiInjectStylesheet('code', css);
this._stylesheetInjectedViaApi = true; this._stylesheetInjectedViaApi = true;
} catch (e) { } catch (e) {
// NOP // NOP

View File

@ -89,8 +89,8 @@ function apiFrameInformationGet() {
return _apiInvoke('frameInformationGet'); return _apiInvoke('frameInformationGet');
} }
function apiInjectStylesheet(css) { function apiInjectStylesheet(type, value) {
return _apiInvoke('injectStylesheet', {css}); return _apiInvoke('injectStylesheet', {type, value});
} }
function apiGetEnvironmentInfo() { function apiGetEnvironmentInfo() {