KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.74k stars 456 forks source link

Error in the function compose.body() #784

Closed kaeevans closed 4 months ago

kaeevans commented 4 months ago

I get this console error when I call compose.body("my reply") for a reply compose box:

jquery.module.min.js:2 Uncaught TypeError: Illegal invocation
    at T.fn.init.<anonymous> (jquery.module.min.js:2:44823)
    at Y (jquery.module.min.js:2:6326)
    at T.fn.init.html (jquery.module.min.js:2:44634)
    at Gmail.api.dom.compose.body (gmail.js:4183:25)
    at eval (eval at <anonymous> (extension.js:49:17), <anonymous>:1:9)
    at extension.js:49:17                        <-- this is where I call compose.body("my reply")
    at handler (gmail.js:2573:21)
    at Gmail.api.observe.trigger_dom (gmail.js:2451:13)
    at Gmail.api.tools.insertion_observer (gmail.js:2797:37)
    at MutationObserver.<anonymous> (gmail.js:2710:39)
guzman-rc commented 4 months ago

This could fix the error:

https://github.com/KartikTalwar/gmail.js/issues/783

kaeevans commented 4 months ago

That fixed it but the simpler solution was using this catch all:

if (window.trustedTypes && window.trustedTypes.createPolicy) {
  window.trustedTypes.createPolicy("default", {
    createHTML: (string) => string,
    createScriptURL: (string) => string,
    createScript: (string) => string,
  });
}
DDorrance90 commented 4 months ago

That fixed it but the simpler solution was using this catch all:

if (window.trustedTypes && window.trustedTypes.createPolicy) {
  window.trustedTypes.createPolicy("default", {
    createHTML: (string) => string,
    createScriptURL: (string) => string,
    createScript: (string) => string,
  });
}

Thank you for that, I was having a similar issue calling add_toolbar_button() with this error:

jquery.module.min.js:2 Uncaught TypeError: Illegal invocation
    at T.fn.init.<anonymous> (jquery.module.min.js:2:44823)
    at Y (jquery.module.min.js:2:6326)
    at T.fn.init.html (jquery.module.min.js:2:44634)
    at create_generic_toolbar_button (gmail.js:3673:16)
    at Gmail.api.tools.add_toolbar_button (gmail.js:3690:16)
    at extension.js:40:29