-
Notifications
You must be signed in to change notification settings - Fork 457
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
Gmail change for innerHTML #779
Comments
Eeek. That sounds like it can cause quite a bit of problems, depending on the complexity of the extension. Would you be willing to upstream and PRs which helps alleviate the issue for now? While normally I've tried to avoid breaking changes in Gmail.js, given how this sounds like a fairly breaking change on Google's end, I might be willing to accept PRs which includes breaking changes, if that is required to solve this problem. |
Talking about how upgraded jQuery solves this... Ive considered for quite a while how it may be time to embrace regular DOM APIs instead of relying on jQuery. Would using plain DOM APIs help us in this case? Or would we just get the same problems none the less? |
we have the local files for jquery and gmail.js in our repo... so what we did for now was replace all the |
should work using plain DOM APIs i think... bc the problem with that change is on the innetHTML that can also be changed for other things and google provide this https://web.dev/articles/trusted-types?hl=es#rewrite_the_offending_code |
@onestep said:
Making that change is a major compatibility break. I'm generally against making breaking changes when one doesn't have to, because usually it involves more work for everyone. If we are to make a breaking change it should be done properly:
If we do this now, it might save us effort down the line... But as mentioned above, there might be even more hurdles down the line. If so, would also this work be worth it, if it has to be redone again soonish? In that case, maybe not doing a breaking change but just updating jQuery to latest beta is an acceptable "middle-ground" while seeing how things play out? Opinions? |
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json
Thank you @DiegoMMR for this extension suggestion to test, Google started to roll out changes to us, but I haven't received it. Thanks to this thread, I was able to replicate a problem and fix it very quickly. For what it's worth, I migrated to new jQuery 4 beta and added only following changes to the codebase, in my case working fine with gmail.js jQuery.isArray = Array.isArray;
jQuery.extend({
htmlPrefilter: createTrustedHTML // Create "magical" trusted HTML as in https://web.dev/articles/trusted-types#create_a_trusted_type_policy
});
this.gmail = new Gmail(jQuery); |
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json - updated some function signatures in type definitions
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json - updated some function signatures in type definitions
thanks to everyone here who jumped in to solve this problem!! I've been hit hard, my gmail.js-based extension totally stopped working over the past few days......! but I followed the instructions here, upgraded to jquery 4 beta, changed all of my innerhtml to actual jquery objects, etc. fingers crossed for the extension review process but yeah. just wanted to give a huge huge thanks. cheers |
…artikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json - updated some function signatures in type definitions
Although this fix renders the extension content, the trustedHtml error still occurs in |
#780) * fix: avoid using deprecated jQuery functions to prepare for jQuery 4 (#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json - updated some function signatures in type definitions * Fixup constructor parameter types. Fix editor-config for typescript too. --------- Co-authored-by: Jostein Kjønigsen <[email protected]>
New version published to npmjs with preliminary changes as version |
The HTML you pass in to the function needs to be converted into "trusted" html using the same technique as the htmlPrefilter for Jquery. I've tested that in my extension and that works without any issues. |
Hello, Did you have observe on "compose" work ? |
I'm having issues with my compose modules too, but haven't had time to look into how/why that's failing yet. |
The issue with observers is this return statement:
For whatever reason An is now the second class, and the first class has no observers so it just returns. I think it should be continue not return... |
Yes it works, I had made a silly mistake, I had passed the |
@josteink I'm having the same issue with the Created following PR for this. |
FYI this PR is merged and now available in v1.1.14. |
@kinkoazc thanks, my bad that I haven't checked for |
No worries. Mistakes happens. You made some huge improvements which helped everyone in the community and the community helped you back. It's how open-source is supposed to work 🙂 |
I'm still having trouble with this. I updated to the latest version of gmail-js and jquery, and I added this to my const createTrustedHTML = trustedTypes.createPolicy("default", {
createHTML: (to_escape) => to_escape,
});
jQuery.isArray = Array.isArray;
jQuery.extend({
htmlPrefilter: createTrustedHTML, // Create "magical" trusted HTML as in https://web.dev/articles/trusted-types#create_a_trusted_type_policy
}); But I'm getting this error:
|
You need the jquery 4 beta. |
I have the jQuery 4 beta. My package.json says |
I don't see you importing/requiring jquery as a package in that example. Maybe that's what you're missing? |
Here's the entire file: const GmailFactory = require("gmail-js");
const jQuery = require("jquery");
const createTrustedHTML = trustedTypes.createPolicy("default", {
createHTML: (to_escape) => to_escape,
});
jQuery.isArray = Array.isArray;
jQuery.extend({
htmlPrefilter: createTrustedHTML, // Create "magical" trusted HTML as in https://web.dev/articles/trusted-types#create_a_trusted_type_policy
});
// don't mess up too bad if we have several gmail.js-based
// extensions loaded at the same time!
window._gmailjs = window._gmailjs || new GmailFactory.Gmail(jQuery); |
Not sure if thats your only error, but I at least spotted this tiny thing: const createTrustedHTML = trustedTypes.createPolicy("default", {
createHTML: (to_escape) => to_escape,
});
jQuery.extend({
htmlPrefilter: createTrustedHTML
}); Here you are passing the whole trusted HTML policy in to jquery, which simply expects a function to convert string to trusted strings. Use this instead: const trustedHTMLpolicy = trustedTypes.createPolicy("default", {
createHTML: (to_escape) => to_escape,
});
jQuery.extend({
htmlPrefilter: trustedHTMLpolicy.createHTML // this is the actual function which jQuery needs
}); |
GmailJS Node Boilerplate gives me an error.
And finally I load the extension. Uncaught TypeError: $ is not a function Could you please help me to correct the error? |
I intended to update the boilerplate but never got around to it, and forgot it completely. Should be updated now. Tested and works. |
Great, now it works but I get the following output: This function is not working properly: |
Weird. Works for me. Howeever, it seems like most things are up and running as they should now, so I just would file that as an individual bug, and see if someone can come up with a PR to fix it. |
It seems that the error occurs with personal accounts: @gmail.com, with professional accounts it works correctly. To fix this error, add these instructions:
to the function: api.get.user_email
|
Something about the way you imported jquery into the boilerplate project fixed my bug. Separate but related issue: the compose.body() function appears to be broken. I get this console error when I call
|
Error when executing the function:
This is my extension.js file
|
Please file these as separate issues. The included details are very nice to have. |
Based on your comments here is a workaround that was working for me, when fixing the problem with jquery 4 beta:
and in my extension.js:
I am not extending jQuery.htmlPrefilter as suggested above. |
Hi Gmail JS team / @mohammedfarhan99 , FYI that I had updated code to refer jQuery & added below code & it is working, const trustedHTMLpolicy = trustedTypes.createPolicy("default", { $.extend({ But gmail.tools.add_toolbar_button() method used to add buttons to toolbar is not working & showing below error in console, Please let me know if anyone had found root for the issue of gmail.tools.add_toolbar_button() not working / share your thoughts on how to address it Thanks in Advance, |
Thanks everyone, after replace with jQuery 4 beta, i got error on gmail.tools.add_compose_button, just to say, this is my fix. jQuery.isArray = Array.isArray; |
Gmail will change and add a trustedHTML policy that doenst allow jquery to load
https://workspaceupdates.googleblog.com/2024/01/extending-trusted-types-to-gmail.html
to test it if you dont have that change you need to install this extension https://chromewebstore.google.com/detail/modheader-modify-http-hea/idgpnmonknjnojddfkpgkljpfnnfcklj
then you need to add this policy
we did a change from
innerHTML
tosetHTML
is a temporal fix that worked but prob is not permamenthttps://developer.mozilla.org/en-US/docs/Web/API/Element/setHTML
but in theory the change to jquery 4 should fix it
https://blog.jquery.com/2024/02/06/jquery-4-0-0-beta/
The text was updated successfully, but these errors were encountered: