Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 37e200c

Browse files
author
Brian Vaughn
committed
Added message to popup with commit sha link
1 parent 9c9d720 commit 37e200c

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

backend/installGlobalHook.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ function installGlobalHook(window: Object) {
2828
return false;
2929
}
3030

31+
function getCommitSha(renderer) {
32+
var version = renderer.version;
33+
if (typeof version === 'string') {
34+
const index = renderer.version.indexOf('-canary-');
35+
if (index > 0) {
36+
return version.substr(index + 8);
37+
}
38+
}
39+
return null;
40+
}
41+
3142
function detectReactBuildType(renderer) {
3243
try {
3344
if (typeof renderer.version === 'string') {
@@ -167,7 +178,8 @@ function installGlobalHook(window: Object) {
167178
'deadcode' :
168179
detectReactBuildType(renderer);
169180
var isCanaryVersion = detectCanaryVersion(renderer);
170-
hook.emit('renderer', {id, isCanaryVersion, renderer, reactBuildType});
181+
var commitSha = getCommitSha(renderer);
182+
hook.emit('renderer', {id, isCanaryVersion, commitSha, renderer, reactBuildType});
171183
return id;
172184
},
173185
_listeners: {},

shells/webextension/popups/shared.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
/* globals chrome */
22

33
document.addEventListener('DOMContentLoaded', function() {
4+
// Add canary message
5+
const commitShaIndex = location.search.indexOf('commitSha=');
6+
if (commitShaIndex >= 0) {
7+
const commitSha = location.search.substr(commitShaIndex + 10);
8+
const textNode = document.createTextNode('You are using a canary build of React that was created from commit ');
9+
const link = document.createElement('a');
10+
link.href = `https://github.com/facebook/react/commit/${commitSha}`;
11+
link.text = commitSha;
12+
const hRule = document.createElement('hr');
13+
const paragraph = document.createElement('p');
14+
paragraph.appendChild(hRule);
15+
paragraph.appendChild(textNode);
16+
paragraph.appendChild(link);
17+
document.body.appendChild(paragraph);
18+
}
19+
420
// Make links work
5-
var links = document.getElementsByTagName('a');
6-
for (var i = 0; i < links.length; i++) {
21+
const links = document.getElementsByTagName('a');
22+
for (let i = 0; i < links.length; i++) {
723
(function() {
8-
var ln = links[i];
9-
var location = ln.href;
10-
ln.onclick = function() {
24+
const link = links[i];
25+
const location = link.href;
26+
link.onclick = function(event) {
27+
event.preventDefault();
1128
chrome.tabs.create({active: true, url: location});
1229
};
1330
})();

shells/webextension/src/GlobalHook.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ window.addEventListener('message', function(evt) {
3030
if (evt.source === window && evt.data && evt.data.source === 'react-devtools-detector') {
3131
lastDetectionResult = {
3232
hasDetectedReact: true,
33+
commitSha: evt.data.commitSha,
3334
isCanaryVersion: evt.data.isCanaryVersion,
3435
reactBuildType: evt.data.reactBuildType,
3536
};
@@ -52,6 +53,7 @@ var detectReact = `
5253
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.on('renderer', function(evt) {
5354
window.postMessage({
5455
source: 'react-devtools-detector',
56+
commitSha: evt.commitSha,
5557
isCanaryVersion: evt.isCanaryVersion,
5658
reactBuildType: evt.reactBuildType,
5759
}, '*');

shells/webextension/src/background.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function doublePipe(one, two) {
7070
two.onDisconnect.addListener(shutdown);
7171
}
7272

73-
function setIconAndPopup(reactBuildType, isCanaryVersion, tabId) {
73+
function setIconAndPopup(reactBuildType, isCanaryVersion, commitSha, tabId) {
7474
var iconType = reactBuildType === 'production' && isCanaryVersion
7575
? 'canary'
7676
: reactBuildType;
@@ -83,9 +83,15 @@ function setIconAndPopup(reactBuildType, isCanaryVersion, tabId) {
8383
'128': 'icons/128-' + iconType + '.png',
8484
},
8585
});
86+
87+
var urlParams = '';
88+
if (commitSha) {
89+
urlParams = '?commitSha=' + commitSha;
90+
}
91+
8692
chrome.browserAction.setPopup({
8793
tabId: tabId,
88-
popup: 'popups/' + reactBuildType + '.html',
94+
popup: 'popups/' + reactBuildType + '.html' + urlParams,
8995
});
9096
}
9197

@@ -96,7 +102,7 @@ function setIconAndPopup(reactBuildType, isCanaryVersion, tabId) {
96102
if (IS_FIREFOX) {
97103
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
98104
if (tab.active && changeInfo.status === 'loading') {
99-
setIconAndPopup('disabled', 'disabled', tabId);
105+
setIconAndPopup('disabled', false, null, tabId);
100106
}
101107
});
102108
}
@@ -118,7 +124,6 @@ chrome.runtime.onMessage.addListener((req, sender) => {
118124
// version of React in React docs, but not in any other case.
119125
reactBuildType = 'production';
120126
}
121-
var isCanaryVersion = req.isCanaryVersion;
122-
setIconAndPopup(reactBuildType, isCanaryVersion, sender.tab.id);
127+
setIconAndPopup(reactBuildType, req.isCanaryVersion, req.commitSha, sender.tab.id);
123128
}
124129
});

0 commit comments

Comments
 (0)