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.

Bytenode breaking JSON.parse() and localStorage.getItem() functions.

See original GitHub issue

Hi there, my code breaks after compiling with bytenode and that it also breaks with javascript-obfuscator. And after long hours of debugging, I’ve come into conclusion that JSON."parse()" and localStorage."getItem()" cannot be altered in any way as it will not function at all. So my question is whether bytenode allows like some sort of exclusion to exclude certain codes/functions from being compiled/obfuscated in which javascript-obfuscator has like /* javascript-obfuscator:disable */ to do so.

PS: These codes/functions are being used with Puppeteer.

localStorages = await page.evaluate(() => JSON.parse(localStorage.getItem('websiteLocalStorage')));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
OsamaAbbascommented, Jan 4, 2021

Another solution is to pass your statements as a string to .evaluate() function. It should work too.

I’m closing the issue now. It you still have a problem feel free to comment and ask for re-opening it.

1reaction
OsamaAbbascommented, Feb 25, 2021

My proposed workaround is to separate the functions that need to be sent to .evaluate() (and similar functions) into a separate .js file.

Something like this:

// main.js, this file can be compiled
const evalFunctions = require('./eval-functions.js');
...
localStorages = await secondTab.evaluate(evalFunctions.xyz);
...
// eval-functions.js, do NOT compile this file

exports.xyz = () => JSON.parse(localStorage.getItem('com.nike.commerce.snkrs.web.credential'));

I hope this solves your issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LocalStorage and JSON.stringify JSON.parse - Stack Overflow
localStorage stores key value pairs as strings only (you can use integer for keys but they get converted to string automatically).
Read more >
How To Store JSON Data In Local Storage — JS, React, Angular
You can store some data in the browser by using localStorage. ... Note that using the JSON.parse() method is not always necessary!
Read more >
Introduction to localStorage and sessionStorage - DigitalOcean
This tutorial features localStorage , but the syntax for ... To read and return stringified values, use the JSON.parse() method.
Read more >
CS 204 Local Storage
getItem (key) returns a value from local storage or null if it doesn't exist. ... JSON.parse() takes a string of JSON and (re-)creates...
Read more >
bytenode - Bountysource
Bytenode breaking JSON.parse() and localStorage.getItem() functions. $ 0 ... getItem()" cannot be altered in any way as it will not function at all....
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