-
Notifications
You must be signed in to change notification settings - Fork 458
Description
Context
In our chrome extension, we inject a button into gmail's toolbar,via gmailjs' add_toolbar_button
button api, via this func (code modified for brevity):
function addButton(){
// we have a check to see if the button is already present, we don't re-add it
gmail.tools.add_toolbar_button(
`
<button>
Click Me!
</button>
`,
() => alert('CLick me!')
)
}
Incident Report
After the newest chrome update to version 129.0.6668.70
, this injected button appears into gmail's toolbar for a couple of seconds and disappears, so to alleviate that we tried adding a setTimeout to where we call this function, which is in the event handlers of hashChange
and load
So previously in these event handlers if we called addButton()
directly now it would change to
setTimeout(addButton, 5000)
,
Although this would make our injected button appear after 4s, it would still disappear once again. But at least now we would notice that our injected button appears on gmail's toolbar dom, but not on gmail's toolbar itself, the reason for this being that the parent element of our injected button has a css style of { display: none }
which was causing our button to not appear in the toolbar
So we modify our above function to also see if the parent's css has display as none
and if it does, then we modify the property of display to 'block'.
So the function is rewritten to accommodate the button's parent css
function addButton(){
//Fetch parent
const toolbar = _gmailjs__jQuery('[gh="tm"]');
const buttonToolbar = toolbar.find('#my-button')
//Compute if button toolbar already has your button, via find or other jquery methods
const doesToolBarHaveMyButton;
if(doesToolBarHaveMyButton){
gmail.tools.add_toolbar_button(
`
<button>
Click Me!
</button>
`,
() => alert('CLick me!')
)
}
} else {
//Check if toolbar's parent has display property as none and update accordingly
const buttonToolBarParent = buttonToolbar.parent()
const parentEl = buttonToolBarParent.parent()
const currentCssValue = parentEl.css('display')
if(currentCss === 'none'){
parentEl.css('display','block')
}
}
Conclusion
This rewrite works, but it feels like this solution is a little hacky and seems like something that's best handled within gmail-js itself. If anyone could pick it up, that would be great. Otherwise, would love some guidance as to the best place to handle this, and a good practice to handle it, since I'm sure gmail-js would have had to handle similar issues in the past