Chrome 扩展:Gmail 导航

Chrome Extension : Gmail navigation

我正在为 Gmail 开发 chrome 扩展。我的扩展程序在电子邮件正文旁边显示了我网站上的数据。

如果我直接转到特定电子邮件或刷新页面,它工作正常。

但是如果我从收件箱转到电子邮件或从一封电子邮件转到另一封电子邮件,那么我的内容脚本就不是 运行。

我不确定是什么原因。

当您从收件箱移至电子邮件时,Gmail 不会重新加载页面,它会动态变化 DOM。你应该使用MutationObserver来处理它。

// 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