mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
f37c7bc653
Stacked on https://github.com/facebook/react/pull/30610 and whats under it. See [last commit](https://github.com/facebook/react/pull/30636/commits/248ddba18608e1bb5ef14c823085a7ff9d7a54a3). Now, we are using [`chrome.storage`](https://developer.chrome.com/docs/extensions/reference/api/storage) to persist settings for the browser extension across different sessions. Once settings are updated from the UI, the `Store` will emit `settingsUpdated` event, and we are going to persist them via `chrome.storage.local.set` in `main/index.js`. When hook is being injected, we are going to pass a `Promise`, which is going to be resolved after the settings are read from the storage via `chrome.storage.local.get` in `hookSettingsInjector.js`.
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
/* global chrome */
|
|
|
|
// We can't use chrome.storage domain from scripts which are injected in ExecutionWorld.MAIN
|
|
// This is the only purpose of this script - to send persisted settings to installHook.js content script
|
|
|
|
async function messageListener(event: MessageEvent) {
|
|
if (event.source !== window) {
|
|
return;
|
|
}
|
|
|
|
if (event.data.source === 'react-devtools-hook-installer') {
|
|
if (event.data.payload.handshake) {
|
|
const settings = await chrome.storage.local.get();
|
|
// If storage was empty (first installation), define default settings
|
|
if (typeof settings.appendComponentStack !== 'boolean') {
|
|
settings.appendComponentStack = true;
|
|
}
|
|
if (typeof settings.breakOnConsoleErrors !== 'boolean') {
|
|
settings.breakOnConsoleErrors = false;
|
|
}
|
|
if (typeof settings.showInlineWarningsAndErrors !== 'boolean') {
|
|
settings.showInlineWarningsAndErrors = true;
|
|
}
|
|
if (typeof settings.hideConsoleLogsInStrictMode !== 'boolean') {
|
|
settings.hideConsoleLogsInStrictMode = false;
|
|
}
|
|
|
|
window.postMessage({
|
|
source: 'react-devtools-hook-settings-injector',
|
|
payload: {settings},
|
|
});
|
|
|
|
window.removeEventListener('message', messageListener);
|
|
}
|
|
}
|
|
}
|
|
|
|
window.addEventListener('message', messageListener);
|
|
window.postMessage({
|
|
source: 'react-devtools-hook-settings-injector',
|
|
payload: {handshake: true},
|
|
});
|