Skip to content

Commit dd4596a

Browse files
committed
Try fix issue with Gmail stealing our click-events.
1 parent fce0ae7 commit dd4596a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
# Changelog
33

4+
## Version 1.0.7
5+
6+
- Fix issues with Gmail preventing click-events on buttons registered
7+
thourgh GmailJS. Closes #648.
8+
49
## Version 1.0.6
510

611
- Fix `gmail.compose.start_compose()`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gmail-js",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "JavaScript API for Gmail (useful for chrome extensions)",
55
"main": "src/gmail.js",
66
"types": "src/gmail.d.ts",

src/gmail.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,25 @@ var Gmail = function(localJQuery) {
24362436
api.tracker.custom_dom_observers[action] = config;
24372437
};
24382438

2439+
2440+
var preventGmailJacking = function() {
2441+
// prevent gmail jacking our click-events!
2442+
2443+
// install event-handler only once!
2444+
if (!api.tracker.jackPreventionInstalled) {
2445+
window.addEventListener("click", (e) => {
2446+
const realTarget = e.path[0];
2447+
const gmailJsButton = realTarget.querySelector(".gmailjs");
2448+
if (gmailJsButton) {
2449+
gmailJsButton.click();
2450+
e.preventDefault();
2451+
}
2452+
});
2453+
api.tracker.jackPreventionInstalled = true;
2454+
}
2455+
};
2456+
2457+
24392458
/**
24402459
Observe DOM nodes being inserted. When a node with a class defined in api.tracker.dom_observers is inserted,
24412460
trigger the related event and fire off any relevant bound callbacks
@@ -2498,14 +2517,18 @@ var Gmail = function(localJQuery) {
24982517
// wait until the gmail interface has finished loading and then
24992518
// execute the passed handler. If interface is already loaded,
25002519
// then will just execute callback
2501-
if(api.dom.inbox_content().length) return callback();
2520+
if(api.dom.inbox_content().length) {
2521+
preventGmailJacking();
2522+
return callback();
2523+
}
25022524
var load_count = 0;
25032525
var delay = 200; // 200ms per check
25042526
var attempts = 50; // try 50 times before giving up & assuming an error
25052527
var timer = setInterval(function() {
25062528
var test = api.dom.inbox_content().length;
25072529
if(test > 0) {
25082530
clearInterval(timer);
2531+
preventGmailJacking();
25092532
return callback();
25102533
} else if(++load_count > attempts) {
25112534
clearInterval(timer);
@@ -3412,7 +3435,7 @@ var Gmail = function(localJQuery) {
34123435
container.attr("class","G-Ni J-J5-Ji");
34133436

34143437
var button = $(document.createElement("div"));
3415-
var buttonClasses = "T-I J-J5-Ji ";
3438+
var buttonClasses = "T-I J-J5-Ji gmailjs ";
34163439
if(styleClass !== undefined &&
34173440
styleClass !== null &&
34183441
styleClass !== ""){
@@ -3451,7 +3474,7 @@ var Gmail = function(localJQuery) {
34513474

34523475
api.tools.add_compose_button = function(composeWindow, content_html, onClickFunction, styleClass) {
34533476
var button = $(document.createElement("div"));
3454-
var buttonClasses = "T-I J-J5-Ji aoO T-I-atl L3 gmailjscomposebutton ";
3477+
var buttonClasses = "T-I J-J5-Ji aoO T-I-atl L3 gmailjs gmailjscomposebutton ";
34553478
if(styleClass !== undefined){
34563479
buttonClasses += styleClass;
34573480
}

0 commit comments

Comments
 (0)