Skip to content

[Bug]: onBeforeRequest url does not include port when used with a custom scheme #38816

@stoarca

Description

@stoarca

Preflight Checklist

Electron Version

25.1.1

What operating system are you using?

Ubuntu

Operating System Version

18.04

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

The following minimal example:

const {app, BrowserWindow, protocol, session} = require('electron');

protocol.registerSchemesAsPrivileged([{
  scheme: 'yolo',
  privileges: {
    standard: true,
    secure: true,
    bypassCSP: true,
    supportFetchAPI: true
  }
}]);

app.whenReady().then(async () => {
  protocol.registerFileProtocol('yolo', (request, callback) => {
    console.log('FILE CALLBACK');
    console.log(request.url);
    callback({url: request.url});
  });
  let win = new BrowserWindow({
    webPreferences: {
      nodeIntegration: true,
      nodeIntegrationInSubFrames: false,
      contextIsolation: false,
    },
  });

  session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
    console.log('BEFORE REQUEST');
    console.log(details.url);
    callback({});
  });

  win.loadURL('yolo://localhost:8000/asdf.html');
});

is expected to print:

BEFORE REQUEST
yolo://localhost:8000/asdf.html
FILE CALLBACK
yolo://localhost:8000/asdf.html

Actual Behavior

Instead, it prints

BEFORE REQUEST
yolo://localhost/asdf.html
FILE CALLBACK
yolo://localhost/asdf.html

(the port is stripped)

Testcase Gist URL

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy