Skip to content

Commit e5abbb8

Browse files
committed
Import a report log with the id specified in the url
1 parent ac998cc commit e5abbb8

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

src/app/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function post(message) {
3333

3434
export function toContentScript(message, shouldStringify, serializeState, serializeAction) {
3535
if (shouldStringify || isCircular) {
36-
if (message.type !== 'ERROR' && message.payload) {
36+
if (message.type !== 'ERROR' && message.type !== 'GET_REPORT' && message.payload) {
3737
message.payload = stringify(message.payload, serializeState);
3838
}
3939
if (message.type !== 'STATE' && message.action) {

src/app/store/configureStore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { compose } from 'redux';
22
import instrument from 'redux-devtools-instrument';
33
import persistState from 'redux-devtools/lib/persistState';
44

5-
function getPersistSession() {
6-
const matches = window.location.href.match(/[?&]debug_session=([^&#]+)\b/);
5+
export function getUrlParam(key) {
6+
const matches = window.location.href.match(new RegExp(`[?&]${key}=([^&#]+)\\b`));
77
return (matches && matches.length > 0) ? matches[1] : null;
88
}
99

@@ -13,7 +13,7 @@ export default function configureStore(
1313
return compose(
1414
instrument(monitorReducer, window.devToolsOptions),
1515
persistState(
16-
getPersistSession(),
16+
getUrlParam('debug_session'),
1717
deserializeState,
1818
deserializeAction
1919
)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export function getReport(id, instance) {
2+
chrome.storage.local.get(['s:hostname', 's:port', 's:secure'], options => {
3+
if (!options['s:hostname'] || !options['s:port']) return;
4+
const url = `${options['s:secure'] ? 'https' : 'http'}://${options['s:hostname']}:${options['s:port']}`;
5+
6+
fetch(url, {
7+
method: 'POST',
8+
headers: {
9+
'content-type': 'application/json'
10+
},
11+
body: JSON.stringify({ op: 'get', id })
12+
}).then(response => {
13+
return response.json();
14+
}).then(json => {
15+
if (!json.payload) return;
16+
window.store.liftedStore.importState(json.payload, instance);
17+
}).catch(function(err) {
18+
console.warn(err);
19+
});
20+
});
21+
}

src/browser/extension/background/messaging.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import updateState from 'remotedev-app/lib/store/updateState';
22
import syncOptions from '../options/syncOptions';
33
import openDevToolsWindow from './openWindow';
4+
import { getReport } from './logging';
5+
46
let panelConnections = {};
57
let tabConnections = {};
68
let monitorConnections = {};
@@ -44,6 +46,10 @@ function messaging(request, sender, sendResponse) {
4446
});
4547
return true;
4648
}
49+
if (request.type === 'GET_REPORT') {
50+
getReport(request.payload, request.id);
51+
return true;
52+
}
4753
if (request.type === 'OPEN') {
4854
let position = 'devtools-left';
4955
if (['remote', 'panel', 'left', 'right', 'bottom'].indexOf(request.position) !== -1) position = 'devtools-' + request.position;

src/browser/extension/inject/pageScript.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getActionsArray, evalAction } from 'remotedev-utils';
22
import createStore from '../../../app/store/createStore';
3-
import configureStore from '../../../app/store/configureStore';
3+
import configureStore, { getUrlParam } from '../../../app/store/configureStore';
44
import { isAllowed } from '../options/syncOptions';
55
import Monitor from '../../../app/service/Monitor';
66
import { getLocalFilter, isFiltered, filterState } from '../../../app/api/filters';
@@ -12,6 +12,7 @@ import {
1212
} from '../../../app/api';
1313

1414
let stores = {};
15+
let reportId;
1516

1617
window.devToolsExtension = function(reducer, preloadedState, config) {
1718
/* eslint-disable no-param-reassign */
@@ -94,6 +95,11 @@ window.devToolsExtension = function(reducer, preloadedState, config) {
9495
actionCreators = getActionsArray(config.actionCreators);
9596
}
9697
relayState(JSON.stringify(actionCreators));
98+
99+
if (reportId) {
100+
relay('GET_REPORT', reportId);
101+
reportId = null;
102+
}
97103
return;
98104
case 'STOP':
99105
monitor.stop();
@@ -114,6 +120,11 @@ window.devToolsExtension = function(reducer, preloadedState, config) {
114120
});
115121

116122
relay('INIT_INSTANCE');
123+
124+
if (typeof reportId === 'undefined') {
125+
reportId = getUrlParam('remotedev_report');
126+
if (reportId) openWindow();
127+
}
117128
}
118129

119130
function handleChange(state, liftedState) {

0 commit comments

Comments
 (0)