-
Notifications
You must be signed in to change notification settings - Fork 51k
[DevTools] improve error handling in extension #26068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,9 @@ chrome.runtime.onConnect.addListener(function(port) { | |
| ports[tab][name] = port; | ||
|
|
||
| if (ports[tab].devtools && ports[tab]['content-script']) { | ||
| doublePipe(ports[tab].devtools, ports[tab]['content-script']); | ||
| doublePipe(ports[tab].devtools, ports[tab]['content-script'], tab); | ||
| // clean up so that we can rebuild the double pipe if the page is reloaded | ||
| ports[tab] = null; | ||
| } | ||
| }); | ||
|
|
||
|
|
@@ -70,14 +72,28 @@ function installProxy(tabId: number) { | |
| } | ||
| } | ||
|
|
||
| function doublePipe(one, two) { | ||
| function doublePipe(one, two, tabId) { | ||
| one.onMessage.addListener(lOne); | ||
| function lOne(message) { | ||
| two.postMessage(message); | ||
| try { | ||
| two.postMessage(message); | ||
| } catch (e) { | ||
| if (__DEV__) { | ||
| console.log(`Broken pipe ${tabId}: `, e); | ||
| } | ||
| shutdown(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the postMessage fail because of a JS exception? I'm not sure if it will happen. I think if we shutdown here not during a page load, the devtools would stop working?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a JS exception. It's a service worker exception when It's weird that the listener was not removed since we already have |
||
| } | ||
| } | ||
| two.onMessage.addListener(lTwo); | ||
| function lTwo(message) { | ||
| one.postMessage(message); | ||
| try { | ||
| one.postMessage(message); | ||
| } catch (e) { | ||
| if (__DEV__) { | ||
| console.log(`Broken pipe ${tabId}: `, e); | ||
| } | ||
| shutdown(); | ||
| } | ||
| } | ||
| function shutdown() { | ||
| one.onMessage.removeListener(lOne); | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be moved to
shutdown? On line 176,ports[id]is accessed. (although I don't know what it does)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed.