Skip to content

Commit 5a386f5

Browse files
committed
Fix devtools source for the extensions background page
1 parent 1eb618f commit 5a386f5

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"webpack": "^1.12.2"
5151
},
5252
"dependencies": {
53-
"crossmessaging": "^0.1.1",
53+
"crossmessaging": "^0.1.2",
5454
"json-stringify-safe": "^5.0.1",
5555
"react": "^0.14.0",
5656
"react-dom": "^0.14.0",

src/browser/extension/background/messaging.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@ import { onConnect, onMessage, sendToTab } from 'crossmessaging';
22
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus.js';
33
let connections = {};
44

5-
function sendNAMessage(port) {
6-
port.postMessage({
7-
na: true,
8-
source: 'redux-page'
9-
});
10-
}
11-
12-
onConnect(() => ({
13-
payload: window.store.liftedStore.getState(),
5+
const naMessage = {
6+
na: true,
147
source: 'redux-page'
15-
}), {}, connections, window.store, sendNAMessage);
8+
};
9+
10+
// Connect to devpanel
11+
onConnect((tabId) => {
12+
console.log('init!', window.store.id, tabId);
13+
if (tabId !== store.id) return naMessage;
14+
return {
15+
payload: window.store.liftedStore.getState(),
16+
source: 'redux-page'
17+
};
18+
}, {}, connections);
1619

1720
function parseJSON(data) {
1821
try {
@@ -28,7 +31,7 @@ function messaging(request, sender) {
2831
const tabId = sender.tab ? sender.tab.id : sender.id;
2932
if (tabId) {
3033
if (request.type === 'PAGE_UNLOADED') {
31-
if (connections[ tabId ]) sendNAMessage(connections[ tabId ]);
34+
if (connections[ tabId ]) connections[ tabId ].postMessage(naMessage);
3235
return true;
3336
}
3437
const payload = typeof request.payload === 'string' ? parseJSON(request.payload) : request.payload;

src/browser/extension/devpanel/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ backgroundPageConnection.onMessage.addListener((message) => {
5050
});
5151

5252
function init(id) {
53+
chrome.devtools.inspectedWindow.eval(
54+
'window.postMessage({' +
55+
'type: \'UPDATE\',' +
56+
'source: \'redux-cs\'' +
57+
'}, \'*\');'
58+
);
5359
backgroundPageConnection.postMessage({ name: 'init', tabId: id });
5460
}
5561

0 commit comments

Comments
 (0)