Gokul N K
Gokul N K

Reputation: 2458

Chrome Extension : Gmail navigation

I am developing a chrome extension for Gmail. My extension shows the data from my website beside the Email body.

Its working fine if I go to a particular email directly or refresh the page.

But say if I move from inbox to a email or from one email to another, then my content scripts are not running.

I am not sure what could be the reason.

Upvotes: 0

Views: 103

Answers (1)

KAdot
KAdot

Reputation: 2077

Gmail doesn't reload the page when you move from inbox to an email, it dynamically changes DOM. You should use MutationObserver to handle it.

// The following code handles new inserted nodes.
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        console.log(mutation.addedNodes);
    });    
});

observer.observe(document.body, {childList: true, subtree: true}); 
// call observer.disconnect(); if you don't need observer anymore

Upvotes: 1

Related Questions