sindresorhus / get-windows

Get metadata about the active window and open windows (title, id, bounds, owner, etc)
MIT License
783 stars 161 forks source link

UnhandledPromiseRejectionWarning: SyntaxError: Unexpected number in JSON at position 10 #158

Open SarathKmrM opened 1 year ago

SarathKmrM commented 1 year ago

Hi team

The module is working fine, but I am getting errors on some specific sites and applications. I am getting below error on https://gitlab.com/users/sign_in Open above link on the browser and try to get activeWindow(), you can find this error

(node:16684) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected number in JSON at position 10
    at JSON.parse (<anonymous>)
    at parseLinux (/var/www/html/focusro-electron-app-apptrack/focusro-app/node_modules/active-win/lib/linux.js:49:15)
    at getWindowInformation (/var/www/html/focusro-electron-app-apptrack/focusro-app/node_modules/active-win/lib/linux.js:92:15)
    at async Timeout._onTimeout (/var/www/html/focusro-electron-app-apptrack/focusro-app/electron-main.js:455:28)
(node:16684) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

Why is this happening ? any solutions ? I am using 8.0.2 version. thanks in advance

seantaylorgmi commented 1 year ago

+1

shunmuga-sundaram commented 1 year ago

+1

richardkevinbox commented 1 year ago

+1

samkennardg commented 1 year ago

i am also facing this issue

ReginaLisa commented 1 year ago

+1

nikess commented 1 year ago

+1

sarathkmrdev commented 1 year ago

+1

asukaminato0721 commented 1 year ago

https://github.com/sindresorhus/active-win/blob/27221e5da0a64025bdec8759605694ea84ff9f68/lib/linux.js#L47-L54

I meet the same problem, after some debug, I change to

    return {
        platform: 'linux',
        title: result['_NET_WM_NAME(UTF8_STRING)'] || result['WM_NAME(STRING)'] || null,
        id: windowId,
        owner: {
            name: result['WM_CLASS(STRING)'].split(',').pop(),
            processId
        },

well, at least it kind of works.

{
  platform: 'linux',
  title: '"apptimer : apptimer \\342\\200\\224 Konsole"',
  id: 150994959,
  owner: { name: ' "konsole"', processId: 169925, path: '/usr/bin/konsole' },
  bounds: { x: 0, y: 42, width: 1920, height: 994 },
  memoryUsage: 217608192
}

about windowId, I found that it will have some problems when listening to a browser or a wine app. For example: become undefined.


and doesn't support CJK