Move apiInjectStylesheet implementation into Backend

This commit is contained in:
toasted-nutbread 2019-12-09 21:56:47 -05:00
parent 01a3432627
commit f786713466
2 changed files with 27 additions and 27 deletions

View File

@ -86,32 +86,7 @@ function apiFrameInformationGet(sender) {
}
function apiInjectStylesheet(css, sender) {
if (!sender.tab) {
return Promise.reject(new Error('Invalid tab'));
}
const tabId = sender.tab.id;
const frameId = sender.frameId;
const details = {
code: css,
runAt: 'document_start',
cssOrigin: 'user',
allFrames: false
};
if (typeof frameId === 'number') {
details.frameId = frameId;
}
return new Promise((resolve, reject) => {
chrome.tabs.insertCSS(tabId, details, () => {
const e = chrome.runtime.lastError;
if (e) {
reject(new Error(e.message));
} else {
resolve();
}
});
});
return utilBackend()._onApiInjectStylesheet({css}, sender);
}
async function apiGetEnvironmentInfo() {

View File

@ -436,7 +436,32 @@ class Backend {
}
_onApiInjectStylesheet({css}, sender) {
return apiInjectStylesheet(css, sender);
if (!sender.tab) {
return Promise.reject(new Error('Invalid tab'));
}
const tabId = sender.tab.id;
const frameId = sender.frameId;
const details = {
code: css,
runAt: 'document_start',
cssOrigin: 'user',
allFrames: false
};
if (typeof frameId === 'number') {
details.frameId = frameId;
}
return new Promise((resolve, reject) => {
chrome.tabs.insertCSS(tabId, details, () => {
const e = chrome.runtime.lastError;
if (e) {
reject(new Error(e.message));
} else {
resolve();
}
});
});
}
_onApiGetEnvironmentInfo() {