question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In fastboot sandbox the `URL` global object is not WHATWG URL

See original GitHub issue

Since Node.js 10 the URL is available as global variable, and it is WHATWG URL API - “Browser-compatible URL class, implemented by following the WHATWG URL Standard”. But under fastboot I can not use new URL(...), because sandbox globals assigns URL to require('url'). https://github.com/ember-fastboot/ember-cli-fastboot/blob/9e0b053cced1189ffeaafa827a386a8f82a1b788/packages/fastboot/src/sandbox.js#L17-L26

It’s very confusing because:

  1. it differs from nodejs, where globalThis.URL === require('url').URL
  2. I can’t write code new URL(...) in app that will be valid for both environments - browser and fastboot. Instead, I have to write like this IS_FASTBOOT ? new URL.URL(...) : new URL(...) or use buildSandboxGlobals to assign URL to require('url').URL instead of default require('url').

In my opinion, the URL global variable in fastboot should be the same as for Node.js:

-   let URL = require('url');
+   let { URL } = require('url');
    let globals = this.globals;

    let sandbox = Object.assign(
      {
        sourceMapSupport,
        console,
        setTimeout,
        clearTimeout,
        URL,

Also, it make sense because support of Node < 10 has been dropped here (#695).

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
simonihmigcommented, Aug 18, 2021

Just tripped over this. In an addon, where I cannot influence the sandbox globals, I had to revert to this ugly check:

const URLConstructor: typeof URL =
        typeof URL === 'function' ? URL : (URL as { URL: typeof URL }).URL;

Would be nice to get this fixed in a stable v3!?

Maybe pass require(‘url’).URL to sandbox, and define a a getter for URL.URL with deprecation warning?

If we want to keep compatibility with the url module and at the same time compatibility with the WHATWG API, that would mean not only exposing URL.URL, but also all the other module exports, right? This is how the export currently looks like when logged:

{
  Url: [Function: Url],
  parse: [Function: urlParse],
  resolve: [Function: urlResolve],
  resolveObject: [Function: urlResolveObject],
  format: [Function: urlFormat],
  URL: [class URL],
  URLSearchParams: [class URLSearchParams],
  domainToASCII: [Function: domainToASCII],
  domainToUnicode: [Function: domainToUnicode],
  pathToFileURL: [Function: pathToFileURL],
  fileURLToPath: [Function: fileURLToPath]
}

Doable, but also kinda ugly.

0reactions
ryanflowerscommented, Nov 29, 2021

Bumping my version of ember-source to 3.22 solved this issue for me. The code throwing the exception is not gone, no other changes needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is There A Bug In Node.Js Pathtofileurl()/Fileurltopath()?
Ask questionsIn fastboot sandbox the URL global object is not WHATWG URL. Since Node.js 10 the URL is available as global variable and...
Read more >
Jest URL.createObjectURL is not a function
This would appear to be as simple as setting up URL on the Global in Jest. Something like describe('download', () => { const...
Read more >
SideQuest-Setup-0.10.18-x64-win.exe, pid
https://url.spec.whatwg.org/#url, SideQuest.exe, ... Object.getPrototypeOf.bind(global.Object);.const getOwnPropertyDescriptor =.global.Object.
Read more >
platform/docs/source.android.com - Git at Google
That is, device implementations MUST NOT alter the triggers or thresholds at which compatibility mode is ... in the Android Open Source Project...
Read more >
What's New - Oracle Linux Yum Server
objenesis-1.2-19.el7 - A library for instantiating Java objects (Update) ... rust-url-2.2.2-4.el9 - URL library for Rust, based on the WHATWG URL Standard ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found