redux-devtools/extension/src/background/logging.ts
Nathan Bierema 24ae412b64 Fix
2025-11-20 08:55:52 -05:00

47 lines
1.3 KiB
TypeScript

import { LIFTED_ACTION } from '@redux-devtools/app';
import { store } from './index';
export function getReport(
reportId: string,
tabId: string | number,
instanceId: number,
) {
chrome.storage.local.get<{
's:hostname': string | undefined;
's:port': string | undefined;
's:secure': string | undefined;
}>(['s:hostname', 's:port', 's:secure'], (options) => {
if (!options['s:hostname'] || !options['s:port']) return;
const url = `${options['s:secure'] ? 'https' : 'http'}://${
options['s:hostname']
}:${options['s:port']}`;
fetch(url, {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ op: 'get', id: reportId }),
})
.then((response) => {
return response.json();
})
.then((json) => {
const { payload, preloadedState } = json;
if (!payload) return;
store.dispatch({
type: LIFTED_ACTION,
message: 'IMPORT',
state: JSON.stringify({ payload, preloadedState }),
id: tabId,
instanceId: `${tabId}/${instanceId}`,
});
})
.catch(function (err) {
/* eslint-disable no-console */
console.warn(err);
/* eslint-enable no-console */
});
});
}