obsproject / obs-browser

CEF-based OBS Studio browser plugin
GNU General Public License v2.0
776 stars 220 forks source link

JS engine can't parse class private methods #329

Closed Magistone closed 2 years ago

Magistone commented 2 years ago

Operating System Info

Windows 10

Other OS

No response

OBS Studio Version

27.1.3

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/2VzpKM_-cgb4287C

OBS Studio Crash Log URL

No response

Expected Behavior

Expected the JS engine to parse the js code successfully

Current Behavior

When the OBS browser JS engine tries to parse the source it logs an error in console at #privateMethod() with the error unexpected token ( Private fields nor public methods are not affected

Steps to Reproduce

  1. Use sample code from the official documentation (copy bellow)
class ClassWithPrivateField {
  #privateField;
}

class ClassWithPrivateMethod {
  #privateMethod() {
    return 'hello world';
  }
}

class ClassWithPrivateStaticField {
  static #PRIVATE_STATIC_FIELD;
}

class ClassWithPrivateStaticMethod {
  static #privateStaticMethod() {
    return 'hello world';
  }
}
  1. add include the js file with the code above to an html file as <script src="theFile.js"></script>
  2. load the created html file in OBS
  3. Open devtools in your browser, select the loaded file. In console there will be error message Uncaught SyntaxError: Unexpected token on the line with #privateMethod()

Screenshot from OBS devtools image

Anything else we should know?

The files in the provided log are custom code, currently unavailable to the public. However, I did confirm that the example given with the copy of syntax code triggers the bug as well.

notr1ch commented 2 years ago

Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields#browser_compatibility, private class methods are not supported by the CEF version used in OBS. Work is underway to update CEF but it is a large undertaking.

Fenrirthviti commented 2 years ago

Status on the upgrade can be followed here: https://github.com/obsproject/obs-studio/discussions/3853