stylus/background/ext-msg.js
tiosgz b8fc4dcaa1 Allow the API to be used by other extensions
This can be useful for example for updating / editing styles from
outside of the browser.

Closes #1264.
2021-08-31 07:57:12 +00:00

22 lines
613 B
JavaScript

/* global msg */
/* global prefs */
'use strict';
window.onMessageExternal = function ({data, target}, sender, sendResponse) {
// Check origin
if (!sender.id || sender.id !== chrome.runtime.id
&& !prefs.get('externals.allowedExtensionIds').includes(sender.id)
) {
return;
}
const allowedAPI =
['openEditor', 'openManage', 'styles', 'sync', 'updater', 'usercss', 'usw'];
// Check content
if (target === 'extension' && data && data.method === 'invokeAPI'
&& data.path && allowedAPI.includes(data.path[0])
) {
msg._onRuntimeMessage({data, target}, sender, sendResponse);
}
};