Skip to content

Commit

Permalink
Refactored to remove need for new webNavigation permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 16, 2019
1 parent c100cc7 commit 527fc4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion shells/browser/chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
},

"permissions": [
"webNavigation",
"file:///*",
"http://*/*",
"https://*/*"
Expand Down
1 change: 0 additions & 1 deletion shells/browser/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
},

"permissions": [
"webNavigation",
"file:///*",
"http://*/*",
"https://*/*"
Expand Down
19 changes: 4 additions & 15 deletions shells/browser/shared/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ function createPanelIfReactLoaded() {
localStorageRemoveItem(LOCAL_STORAGE_SUPPORTS_PROFILING_KEY);
}

if (store !== null) {
profilingData = store.profilerStore.profilingData;
}

store = new Store(bridge, {
isProfiling,
supportsReloadAndProfile: getBrowserName() === 'Chrome',
Expand Down Expand Up @@ -266,21 +270,6 @@ function createPanelIfReactLoaded() {

chrome.devtools.network.onNavigated.removeListener(checkPageForReact);

// Shutdown bridge before a new page is loaded.
chrome.webNavigation.onBeforeNavigate.addListener(
function onBeforeNavigate(details) {
// Ignore navigation events from other tabs (or from within frames).
if (details.tabId !== tabId || details.frameId !== 0) {
return;
}

// `bridge.shutdown()` will remove all listeners we added, so we don't have to.
bridge.shutdown();

profilingData = store.profilerStore.profilingData;
}
);

// Re-initialize DevTools panel when a new page is loaded.
chrome.devtools.network.onNavigated.addListener(function onNavigated() {
// Re-initialize saved filters on navigation,
Expand Down
12 changes: 11 additions & 1 deletion src/devtools/views/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import '@reach/menu-button/styles.css';
import '@reach/tooltip/styles.css';

import React, { useMemo, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';
import Store from '../store';
import { BridgeContext, StoreContext } from './context';
import Components from './Components/Components';
Expand Down Expand Up @@ -103,6 +103,16 @@ export default function DevTools({
[canViewElementSourceFunction, viewElementSourceFunction]
);

useEffect(() => {
return () => {
try {
bridge.shutdown()
} catch (error) {
// Attempting to use a disconnected port.
}
};
}, [bridge]);

return (
<BridgeContext.Provider value={bridge}>
<StoreContext.Provider value={store}>
Expand Down

0 comments on commit 527fc4a

Please sign in to comment.