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

UnhandledPromiseRejectionWarning: SyntaxError: Bad escaped character in JSON at position 12 #170

Open
maninder-aapnainfotech opened this issue Aug 10, 2023 · 0 comments

Comments

@maninder-aapnainfotech
Copy link

maninder-aapnainfotech commented Aug 10, 2023

Hi, Just wanted to report an issue due to which error above error is being thrown. I am using this great library for my Electron app. When my currently opened window is browser either chrome or Mozilla and I simple do:

let currentWindow = await activeWindow({});

I get following error in case of some titles:

(node:85881) UnhandledPromiseRejectionWarning: SyntaxError: Bad escaped character in JSON at position 12
    at JSON.parse (<anonymous>)
    at parseLinux (/node_modules/active-win/lib/linux.js:49:15)
    at getWindowInformation (/node_modules/active-win/lib/linux.js:93:15)

I suspect that it is due to title containing some special characters that are not being parsed by JSON.parse on line 49 in /node_modules/active-win/lib/linux.js

Following are the title that are returned in the result object when I log them:

 "New Issue \302\267 sindresorhus/active-win - Google Chrome"

  " TEAMTRACKER \342\200\224 Mozilla Firefox"

I had to return :

title: (result['_NET_WM_NAME(UTF8_STRING)'] || result['WM_NAME(STRING)'])

Instead of :

title: JSON.parse(result['_NET_WM_NAME(UTF8_STRING)'] || result['WM_NAME(STRING)']) || null,

Then, had to escape characters in my code before saving title to the DB.

Platform is : Ubuntu 20.04

I hope above issue makes sense.

Thanks

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

No branches or pull requests

1 participant