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.

"commonObj" and "opList" hash difference between Node.js and Chromium environments

See original GitHub issue

The goal:

I’m trying to get the same hash of the commonObjs and opList objects ( collections ) in both the Chromium and Node.js environment. These “hashes” I’m trying to get are Sha256 hashes of the JSON stringified commonObjs and opList objects.

The issue:

The issue is that I’m getting a different hash of the opList and commonObjs objects in the two different environments ( Node.js and the Browser ). My assumption is that the structure of the objects is different.

I wish that this can be amended by a simple configuration option, but it could be something tied to the environment that can’t be helped.

Configuration:

Web browser: Chromium Version 89.0.4389.114 (Developer Build) built on Debian 10.9, running on Debian 10.9 (64-bit) OS: Debian 10.9 PDF.js version: 2.7.570 Node.js version: 10.24.1 The gulp configuration used for building the libraries in both environments: gulp minified-legacy

How to reproduce:

Try out the code in this repository: https://github.com/m-majetic/pdfjs-environment-differences

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Snuffleupaguscommented, May 4, 2021

The issue is that I’m getting a different hash of the opList and commonObjs objects in the two different environments ( Node.js and the Browser ). […] This is what I’m trying to do with the opList and commonObjs objects after I extract them from the page:

var opListHash = sha256(JSON.stringify(opList))
console.log("This is the opList hash", opListHash);
var commonObjHash = sha256(JSON.stringify(page.commonObjs))
console.log("This is the commonObj hash", commonObjHash);

Thank you; that’s a lot clearer and it also saves me some time (by not having to clone/run your code).

Unfortunately that’s not really a use-case that’s relevant for e.g. the viewer, and as such we can’t/won’t guarantee that it behaves identically when comparing e.g. browsers and Node.js environments. Please note that the PDF.js library is/was written primarily for usage in browsers, with support for Node.js essentially tacked on afterwards (which unfortunately shows), and we thus by default modify some options to prevent bugs specifically in Node.js environments; see https://github.com/mozilla/pdf.js/blob/master/src/display/api_compatibility.js

Most likely, the differing default options in browsers/Node.js should explain what you’re seeing. You can obviously set the options manually, when calling getDocument, such that you get the same behaviour in all environments.

0reactions
m-majeticcommented, May 5, 2021

Thank you !

I will try out different options and see if they make any difference.

I’d consider this issue closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Difference Between Node.js 10 LTS and Node.js 12 LTS
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Read more >
Difference between Node.JS and Javascript - GeeksforGeeks
1. NodeJS : NodeJS is a cross-platform and opensource Javascript runtime environment that allows the javascript to be run on the server-side.
Read more >
JavaScript vs Node JS | Topmost 3 Comparison you need to ...
Guide to JavaScript vs Node JS. Here we have discussed head to head comparison, key difference along with infographics and comparison table respectively....
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
Mistake #1: Blocking the event loop. JavaScript in Node.js (just like in the browser) provides a single threaded environment. This means that no...
Read more >
Appropriate hashbang for Node.js scripts - Stack Overflow
I'd rather have the script run as an executable for either environment as long as node is installed rather than have one or...
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