Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: polyfill.js

Issue 29582716: Issue 4579 - Ignore runtime.lastError caused by wrapper (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use regex Created Oct. 20, 2017, 1:43 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: polyfill.js
===================================================================
--- a/polyfill.js
+++ b/polyfill.js
@@ -38,16 +38,24 @@
"tabs.sendMessage",
"tabs.update",
"webNavigation.getAllFrames",
"webRequest.handlerBehaviorChanged",
"windows.create",
"windows.update"
];
+ // Since we add a callback for all messaging API calls in our wrappers,
+ // Chrome assumes we're interested in the response; when there's no response,
+ // it sets runtime.lastError
+ const portClosedBeforeResponseError =
+ // Older versions of Chrome have a typo:
+ // https://crrev.com/c33f51726eacdcc1a487b21a13611f7eab580d6d
+ /^The message port closed before a res?ponse was received\.$/;
+
function wrapAPI(api)
{
let object = browser;
let path = api.split(".");
let name = path.pop();
for (let node of path)
{
@@ -73,17 +81,17 @@
if (typeof args[args.length - 1] == "undefined")
args.pop();
return new Promise((resolve, reject) =>
{
func.call(object, ...args, result =>
{
let error = browser.runtime.lastError;
- if (error)
+ if (error && !portClosedBeforeResponseError.test(error.message))
{
// runtime.lastError is already an Error instance on Edge, while on
// Chrome it is a plain object with only a message property.
if (!(error instanceof Error))
{
error = new Error(error.message);
// Add a more helpful stack trace.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld