Refactored to remove need for new webNavigation permission
Brian Vaughn committed
Aug 15, 2019 at 17:34 UTC
527fc4a63f497db1f370a8312807c2a68147edec
4 files changed
+15
-18
shells/browser/chrome/manifest.json
-1
@@ -41,7 +41,6 @@
41
},
42
43
"permissions": [
44
- "webNavigation",
44
"file:///*",
45
"http://*/*",
46
"https://*/*"
shells/browser/firefox/manifest.json
-1
@@ -45,7 +45,6 @@
45
},
46
47
"permissions": [
48
- "webNavigation",
48
"file:///*",
49
"http://*/*",
50
"https://*/*"
shells/browser/shared/src/main.js
+4
-15
@@ -117,6 +117,10 @@ function createPanelIfReactLoaded() {
117
localStorageRemoveItem(LOCAL_STORAGE_SUPPORTS_PROFILING_KEY);
118
}
119
120
+ if (store !== null) {
121
+ profilingData = store.profilerStore.profilingData;
122
+ }
123
+
124
store = new Store(bridge, {
125
isProfiling,
126
supportsReloadAndProfile: getBrowserName() === 'Chrome',
@@ -266,21 +270,6 @@ function createPanelIfReactLoaded() {
270
271
chrome.devtools.network.onNavigated.removeListener(checkPageForReact);
272
269
- // Shutdown bridge before a new page is loaded.
270
- chrome.webNavigation.onBeforeNavigate.addListener(
271
- function onBeforeNavigate(details) {
272
- // Ignore navigation events from other tabs (or from within frames).
273
- if (details.tabId !== tabId || details.frameId !== 0) {
274
- return;
275
- }
276
-
277
- // `bridge.shutdown()` will remove all listeners we added, so we don't have to.
278
- bridge.shutdown();
279
-
280
- profilingData = store.profilerStore.profilingData;
281
- }
282
- );
283
-
273
// Re-initialize DevTools panel when a new page is loaded.
274
chrome.devtools.network.onNavigated.addListener(function onNavigated() {
275
// Re-initialize saved filters on navigation,
src/devtools/views/DevTools.js
+11
-1
@@ -5,7 +5,7 @@
5
import '@reach/menu-button/styles.css';
6
import '@reach/tooltip/styles.css';
7
8
-import React, { useMemo, useState } from 'react';
8
+import React, { useEffect, useMemo, useState } from 'react';
9
import Store from '../store';
10
import { BridgeContext, StoreContext } from './context';
11
import Components from './Components/Components';
@@ -103,6 +103,16 @@ export default function DevTools({
103
[canViewElementSourceFunction, viewElementSourceFunction]
104
);
105
106
+ useEffect(() => {
107
+ return () => {
108
+ try {
109
+ bridge.shutdown()
110
+ } catch (error) {
111
+ // Attempting to use a disconnected port.
112
+ }
113
+ };
114
+ }, [bridge]);
115
+
116
return (
117
<BridgeContext.Provider value={bridge}>
118
<StoreContext.Provider value={store}>