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

[api-minor] Use the Fetch API, when supported, to load PDF documents in Node.js environments #17706

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

Snuffleupagus
Copy link
Collaborator

Given that modern Node.js versions now implement support for a fair number of "browser" APIs, we can utilize the standard Fetch API to load PDF documents that are specified via http/https URLs.

Please find compatibility information at:

@Snuffleupagus
Copy link
Collaborator Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/b56126603fddbe1/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/2b9e009f677d77f/output.txt

@nicolo-ribaudo
Copy link
Contributor

Given that in package.json you require Node.js 18+ (

pdf.js/package.json

Lines 74 to 76 in 72b8b29

"engines": {
"node": ">=18"
},
), are there still cases in which fetch is not supported?

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Feb 21, 2024

are there still cases in which fetch is not supported?

Yes, according to the Node.js documentation it can still be manually disabled in even the latest version; see https://nodejs.org/docs/latest-v21.x/api/cli.html#--no-experimental-fetch

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/b56126603fddbe1/output.txt

Total script time: 24.86 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 12
  different first/second rendering: 2

Image differences available at: http://54.241.84.105:8877/b56126603fddbe1/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/2b9e009f677d77f/output.txt

Total script time: 39.06 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 6

Image differences available at: http://54.193.163.58:8877/2b9e009f677d77f/reftest-analyzer.html#web=eq.log

…in Node.js environments

Given that modern Node.js versions now implement support for a fair number of "browser" APIs, we can utilize the standard Fetch API to load PDF documents that are specified via http/https URLs.

Please find compatibility information at:
 - https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility
 - https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch
 - https://developer.mozilla.org/en-US/docs/Web/API/Response#browser_compatibility
 - https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#response
@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/9ea7f5765b6fa01/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/b93f2cfe74533c4/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/b93f2cfe74533c4/output.txt

Total script time: 2.35 mins

  • Unit Tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/9ea7f5765b6fa01/output.txt

Total script time: 10.25 mins

  • Unit Tests: Passed

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Mar 19, 2024

@calixteman Gentle review ping here, and for #17691.

(Normally I'd ask Tim to review these sort of patches, but he's unfortunately not been around for awhile.)

Copy link
Contributor

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@Snuffleupagus Snuffleupagus merged commit 0022310 into mozilla:master Mar 19, 2024
9 checks passed
@Snuffleupagus Snuffleupagus deleted the Node-Fetch-API branch March 19, 2024 10:04
@timvandermeij
Copy link
Contributor

timvandermeij commented Mar 20, 2024

(Normally I'd ask Tim to review these sort of patches, but he's unfortunately not been around for awhile.)

Yes, I have been quite busy the last weeks and also had some days off, but I'm back again :-)

This also looks really good to me; thanks for doing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants