Skip to content
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

fix: make sure invalid URL loads promises are fulfilled. #41194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/browser/api/web-contents.ts
Expand Up @@ -352,12 +352,12 @@
removeListeners();
resolve();
};
let error: LoadError | undefined;
const rejectAndCleanup = ({ errorCode, errorDescription, url }: LoadError) => {
const err = new Error(`${errorDescription} (${errorCode}) loading '${typeof url === 'string' ? url.substr(0, 2048) : url}'`);
Object.assign(err, { errno: errorCode, code: errorDescription, url });
removeListeners();

Check failure on line 359 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 28-x-y

lib/browser/api/web-contents.ts#L355-L359

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.

Check failure on line 359 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 28-x-y

lib/browser/api/web-contents.ts#L355-L359

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.
reject(err);

Check failure on line 360 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 29-x-y

lib/browser/api/web-contents.ts#L356-L360

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.

Check failure on line 360 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 29-x-y

lib/browser/api/web-contents.ts#L356-L360

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.
};
const finishListener = () => {
if (error) {
Expand All @@ -366,11 +366,6 @@
resolveAndCleanup();
}
};
const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
if (!error && isMainFrame) {
error = { errorCode, errorDescription, url: validatedURL };
}
};

let navigationStarted = false;
let browserInitiatedInPageNavigation = false;
Expand All @@ -392,6 +387,14 @@
navigationStarted = true;
}
};
const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
if (!error && isMainFrame) {
error = { errorCode, errorDescription, url: validatedURL };
}
if (!navigationStarted && isMainFrame) {
finishListener();
}
};
const stopLoadingListener = () => {
// By the time we get here, either 'finish' or 'fail' should have fired
// if the navigation occurred. However, in some situations (e.g. when
Expand Down Expand Up @@ -433,11 +436,11 @@
};

WebContents.prototype.setWindowOpenHandler = function (handler: (details: Electron.HandlerDetails) => ({action: 'deny'} | {action: 'allow', overrideBrowserWindowOptions?: BrowserWindowConstructorOptions, outlivesOpener?: boolean})) {
this._windowOpenHandler = handler;
};

WebContents.prototype._callWindowOpenHandler = function (event: Electron.Event, details: Electron.HandlerDetails): {browserWindowConstructorOptions: BrowserWindowConstructorOptions | null, outlivesOpener: boolean} {
const defaultResponse = {

Check failure on line 443 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 27-x-y

lib/browser/api/web-contents.ts#L439-L443

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.

Check failure on line 443 in lib/browser/api/web-contents.ts

View check run for this annotation

trop / Backportable? - 27-x-y

lib/browser/api/web-contents.ts#L439-L443

Patch Conflict
Raw output
++<<<<<<< HEAD
 +    const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
 +      if (isMainFrame) {
 +        rejectAndCleanup(errorCode, errorDescription, validatedURL);
        }
      };
++=======
++>>>>>>> fix: make sure invalid URL loads promisses are fulfilled.
browserWindowConstructorOptions: null,
outlivesOpener: false
};
Expand Down
4 changes: 4 additions & 0 deletions spec/api-web-contents-spec.ts
Expand Up @@ -519,6 +519,10 @@ describe('webContents module', () => {
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
});

it('invalid URL load rejects', async () => {
await expect(w.loadURL('invalidURL')).to.eventually.be.rejected();
});
});

describe('getFocusedWebContents() API', () => {
Expand Down