nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

URL.createObjectURL fails on 0.76.1

Open Kruithne opened this issue 1 year ago • 13 comments

Issue Type

Before opening an issue, please search and see if it has already been raised.

  • [x] Bug Report

  • [ ] Feature Request

  • [x] Successfully reproduced against the latest version of NW.js?

Please use our mailing list or Gitter chatroom to ask questions. The issue tracker is only for bugs and feature requests, in English only. Please note that issues without a repro or code snippet are less likely to be resolved.

Current/Missing Behavior

URL.createObjectURL(new Blob([])) is the minimal code needed to reproduce the issue. In 0.76.1 the following error message is produced, regardless of input.

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.

Expected/Proposed Behavior

The expected behavior is that a URL to the blob is returned, such as:

blob:chrome-extension://hjnamambhlpahhgnmkmdplebghbjncpm/b1957c09-3e5c-48d3-b545-8052ddb77d3c

This works as expected on 0.75.0.

Additional Info

  • Operating System: Windows
  • NW.js Version: 0.76.1
  • Repro Link:
  • Code snippet: URL.createObjectURL(new Blob([]))
  • Crash report:

Kruithne avatar May 24 '23 14:05 Kruithne

It works for me. I started nw, opened the devtools window and then posted the snippet.

rogerwang avatar May 26 '23 21:05 rogerwang

From my testing, this is only broken inside workers, not on the main thread

  • Worker disabled: https://drive.google.com/file/d/1KO2yJpoG3yo7fXO0i64iWeTAwpZG_5-A/view?usp=drive_link

  • Worker enabled: https://drive.google.com/file/d/1_k4_dQT8B1XWPcjUNGnqAAdNGaMxV330/view?usp=drive_link

(Sorry, file too big for Github)

The bug still happens in 0.77.0

skymen avatar Jun 12 '23 21:06 skymen

This issue seems to be resolved in 0.78.1

Laserwolve avatar Aug 02 '23 17:08 Laserwolve

This issue seems to be resolved in 0.78.1

Still failing for me.

johnyc3 avatar Aug 30 '23 06:08 johnyc3

Same fail on 0.79.1 win64 Same code works fine on 0.75.1

anker9 avatar Sep 03 '23 12:09 anker9

I have the same problem with pixi.js on 0.79.1 win64 while pixi.js try to load asset

ellementul avatar Sep 18 '23 07:09 ellementul

Could you provide a small code sample to reproduce, not an entire application?

rogerwang avatar Sep 19 '23 21:09 rogerwang

I think I found a minimal repro for this: nwjs-issue8075.zip

It's true that URL.createObjectURL(blob) fails in a worker only in recent versions of NW.js, but only when specifying "chromium-args": "--enable-node-worker" in package.json, which some frameworks (like ours) do.

In this case, in the context of the worker, the Blob constructor actually appears to be a version from Node.js (apparently from node:internal/blob) that overrides the browser one. Therefore since it's not a real Blob that the browser understands, methods like URL.createObjectURL fail, but also checks like instanceof Blob also fail.

Hopefully this is enough information to be able to fix the issue now - we're seeing reports of this from time to time (e.g. here).

AshleyScirra avatar Sep 27 '23 10:09 AshleyScirra

Any news on this? We are still getting reports of this causing problems, e.g.: https://github.com/Scirra/Construct-bugs/issues/7466 My previous comment includes a minimal repro and appears to identify the --enable-node-worker command line argument as the problem.

AshleyScirra avatar Oct 16 '23 16:10 AshleyScirra

Lỗi 3d object xuất njsw đã được sửa chưa?

sieusaovang avatar Nov 07 '23 03:11 sieusaovang

Any update on this? We had to disable the worker in our game because of this bug, and now getting lots of reports of poor performance from users..

dop2000 avatar Nov 18 '23 04:11 dop2000

Has any NW.js developer had the chance to review my minimal repro yet? Tagging @rogerwang for attention. We're still getting regular reports of this, e.g. here and here, both posted today.

AshleyScirra avatar Nov 22 '23 11:11 AshleyScirra

Another report of this today here. Any news?

AshleyScirra avatar Dec 15 '23 17:12 AshleyScirra

Please test this build: https://dl.nwjs.io/live-build/nw85/20240305-222312/9b99df3ea/v0.85.1/

rogerwang avatar Mar 06 '24 05:03 rogerwang

Thank you, @rogerwang !

@AshleyScirra , I tested in remote preview and it appears to be working. Is it possible to build a C3 project with this new version (85.1)?

dop2000 avatar Mar 06 '24 05:03 dop2000

@rogerwang - is an official NW.js 0.85.1 release coming up for this? Apparently the issue is affecting some Construct games, and it would be useful to know if a release is scheduled, or if we ought to be using a one-off build (which I'm a bit reluctant about as normally nightly releases are not as reliable)

AshleyScirra avatar Mar 07 '24 14:03 AshleyScirra

The fix is released with 0.86.0

rogerwang avatar Apr 02 '24 17:04 rogerwang

@rogerwang - thanks for the fix!

AshleyScirra avatar Apr 03 '24 09:04 AshleyScirra

~~By gods! Thank you! This issue was blocking ct.js update to use WebGPU as the issue broke pixi.js v8.~~ Nnope, see the next comment

CosmoMyzrailGorynych avatar May 02 '24 10:05 CosmoMyzrailGorynych

@rogerwang apparently there are still issues with createObjectURL. Tested in v0.86.0 and 0.87.0 on Windows. URL.createObjectURL(new Blob([])) — throws the same error.

My chromium args are:

  "chromium-args": "--mixed-context --enable-features=nw2 --load-extensions --force-color-profile=srgb --disable-features=ColorCorrectRendering",

Edit: removing --mixed-content fixes the issue (but breaks my app, so it is still an issue)

CosmoMyzrailGorynych avatar May 03 '24 11:05 CosmoMyzrailGorynych

@rogerwang the same error happens on nw.js-enabled webview tags. Removing allownw attribute on them is enough to fix the error — the price is, again, not great.

CosmoMyzrailGorynych avatar May 11 '24 09:05 CosmoMyzrailGorynych

I think I found a minimal repro for this: nwjs-issue8075.zip

It's true that URL.createObjectURL(blob) fails in a worker only in recent versions of NW.js, but only when specifying "chromium-args": "--enable-node-worker" in package.json, which some frameworks (like ours) do.

In this case, in the context of the worker, the Blob constructor actually appears to be a version from Node.js (apparently from node:internal/blob) that overrides the browser one. Therefore since it's not a real Blob that the browser understands, methods like URL.createObjectURL fail, but also checks like instanceof Blob also fail.

Hopefully this is enough information to be able to fix the issue now - we're seeing reports of this from time to time (e.g. here).

Thanks to the error cause analyzed by @AshleyScirra , I found a temporary solution:

<!-- Fix Blob Start -->
<script>delete window.Blob;</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/Blob.min.js"></script>
<!-- Fix Blob End -->

<script>
    const objectURL = URL.createObjectURL(new Blob(["test"]));
    console.log(objectURL); // 'data:;base64,dGVzdA=='
</script>

But it is still a problem, I hope it can be solved reasonably.

ssnangua avatar Jul 16 '24 10:07 ssnangua