mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-12-10 03:34:17 +03:00
47 lines
1.3 KiB
TypeScript
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 */
|
|
});
|
|
});
|
|
}
|