mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.66k stars 2.93k forks source link

mp.input.get({opened: }) SyntaxError: JSON:1: unexpected character: 'u' #15301

Closed Bad-ptr closed 1 week ago

Bad-ptr commented 1 week ago

mpv Information

mpv v0.39.0-325-gd66ed2d8 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Nov 10 2024 00:40:04
libplacebo version: v7.349.0 (v7.349.0-19-g118d810-dirty)
FFmpeg version: N-117737-g10c02decc
FFmpeg library versions:
   libavcodec      61.24.100
   libavdevice     61.4.100
   libavfilter     10.6.101
   libavformat     61.9.100
   libavutil       59.46.100
   libswresample   5.4.100
   libswscale      8.9.101

Other Information

- Windows version: 10
- GPU model, driver and version:
- Source of mpv:
- Latest known working version: v0.38
- Issue started after the following happened: updating to v0.39

Reproduction Steps

Install mpv or mpv-git using scoop in windows:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop bucket add extras
scoop install mpv
# or scoop install mpv-git

Create a script in mpv_home/scripts/testinput/main.js with contents:

function test_opened() {
    print("OPENED");
}
function test() {
    mp.input.get({opened: test_opened,});
}
mp.register_script_message('test_input_opened', test);

Add keybinding in input.conf: CTRL+9 script-message-to testinput test_input_opened

Start mpv, press CTRL+9

Expected Behavior

No errors.

Actual Behavior

[testinput] SyntaxError: JSON:1: unexpected character: 'u'
[testinput]     at JSON.parse (native)
[testinput]     at @/defaults.js:656
[testinput]     at Function.prototype.apply (native)
[testinput]     at dispatch_message (@/defaults.js:122)
[testinput]     at dispatch_event (@/defaults.js:52)
[testinput]     at mp_event_loop (@/defaults.js:793)
[testinput]     at run_script (native)
[testinput] Could not load js script mpv_home/scripts/testinput/main.js

Log File

mpv_output.txt

[   7.436][d][cplayer] Run command: script-message-to, flags=73, args=[target="testinput", args="test_input_opened"]
[   7.436][d][cplayer] Run command: script-message-to, flags=64, args=[target="console", args="get-input", args="testinput", args="{}"]
[   7.461][d][cplayer] Run command: script-message-to, flags=64, args=[target="testinput", args="input-event", args="opened"]
[   7.461][d][cplayer] Run command: define-section, flags=64, args=[name="input_console", contents="", flags="default"]
[   7.461][d][cplayer] Run command: enable-section, flags=64, args=[name="input_console", flags="allow-hide-cursor+allow-vo-dragging"]
[   7.461][f][testinput] SyntaxError: JSON:1: unexpected character: 'u'
[   7.461][f][testinput]    at JSON.parse (native)
[   7.461][f][testinput]    at @/defaults.js:656
[   7.461][f][testinput]    at Function.prototype.apply (native)
[   7.461][f][testinput]    at dispatch_message (@/defaults.js:122)
[   7.461][f][testinput]    at dispatch_event (@/defaults.js:52)
[   7.461][f][testinput]    at mp_event_loop (@/defaults.js:793)
[   7.461][f][testinput]    at run_script (native)
[   7.461][d][cplayer] Run command: define-section, flags=64, args=[name="input_forced_console", contents="esc script-binding console/_console_1\nctrl+[ script-binding console/_console_2\nenter script-binding console/_console_3\nkp_enter script-binding console/_console_4\nshift+enter script-binding console/_console_5\nctrl+j script-binding console/_console_6\nctrl+m script-binding console/_console_7\nbs script-binding console/_console_8\nshift+bs script-binding console/_console_9\nctrl+h script-binding console/_console_10\ndel script-binding console/_console_11\nshift+del script-binding console/_console_12\nins script-binding console/_console_13\nshift+ins script-binding console/_console_14\nmbtn_mid script-binding console/_console_15\nmbtn_right script-binding console/_console_16\nleft script-binding console/_console_17\nctrl+b script-binding console/_console_18\nright script-binding console/_console_19\nctrl+f script-binding console/_console_20\nup script-binding console/_console_21\nctrl+p script-binding console/_console_22\nwheel_up script-binding console/_console_23\ndown script-binding console/_console_24\nctrl+n script-binding console/_console_25\nwheel_down script-binding console/_console_26\nwheel_left script-binding console/_console_27\nwheel_right script-binding console/_console_28\nctrl+left script-binding console/_console_29\nalt+b script-binding console/_console_30\nctrl+right script-binding console/_console_31\nalt+f script-binding console/_console_32\ntab script-binding console/_console_33\nctrl+i script-binding console/_console_34\nshift+tab script-binding console/_console_35\nctrl+a script-binding console/_console_36\nhome script-binding console/_console_37\nctrl+e script-binding console/_console_38\nend script-binding console/_console_39\npgup script-binding console/_console_40\npgdwn script-binding console/_console_41\nctrl+r script-binding console/_console_42\nctrl+c script-binding console/_console_43\nctrl+d script-binding console/_console_44\nctrl+k script-binding console/_console_45\nctrl+l script-binding console/_console_46\nctrl+u script-binding console/_console_47\nctrl+v script-binding console/_console_48\nmeta+v script-binding console/_console_49\nctrl+bs script-binding console/_console_50\nctrl+w script-binding console/_console_51\nctrl+del script-binding console/_console_52\nalt+d script-binding console/_console_53\nkp_dec script-binding console/_console_54\nkp_add script-binding console/_console_55\nkp_subtract script-binding console/_console_56\nkp_multiply script-binding console/_console_57\nkp_divide script-binding console/_console_58\nkp0 script-binding console/_console_59\nkp1 script-binding console/_console_60\nkp2 script-binding console/_console_61\nkp3 script-binding console/_console_62\nkp4 script-binding console/_console_63\nkp5 script-binding console/_console_64\nkp6 script-binding console/_console_65\nkp7 script-binding console/_console_66\nkp8 script-binding console/_console_67\nkp9 script-binding console/_console_68\nany_unicode script-binding console/_console_text\n", flags="force"]
[   7.462][d][cplayer] Run command: enable-section, flags=64, args=[name="input_forced_console", flags="allow-hide-cursor+allow-vo-dragging"]
[   7.462][e][testinput] Could not load js script mpv_home/scripts/testinput/main.js
[   7.462][d][testinput] Exiting...

Sample Files

testinput.zip

I carefully read all instruction and confirm that I did the following:

llyyr commented 1 week ago

Provide a full log file with --no-config or minimal config required to reproduce the issue

edit: eb4c6be6306ee17846cd88b50460e10967dea951

guidocella commented 1 week ago

Calling JSON.parse(undefined) causes this error.

Bad-ptr commented 1 week ago

I confirm that @guidocella's commits solve the issue.