Javascript gmail因以下代码崩溃

Javascript gmail因以下代码崩溃,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,my chrome扩展的用例是突出显示文本,如果文本与主题列表匹配,则在gmail消息中创建一个超链接来突出显示这些文本。尽管gmail崩溃了,我还是尝试了6个主题。在real中,主题列表将为1000+ 我所做的是在加载文档时,调用了fetchTopics函数(在real中,调用api来获取主题)在该函数中,我迭代了topicData对象,将主题逐个传递给searchPage函数,并将其分配给re变量,以检查提供的主题是否与gmail收件箱消息中的文本匹配 这是我的密码 var topicDat

my chrome扩展的用例是突出显示文本,如果文本与主题列表匹配,则在gmail消息中创建一个超链接来突出显示这些文本。尽管gmail崩溃了,我还是尝试了6个主题。在real中,主题列表将为1000+

我所做的是在加载文档时,调用了fetchTopics函数(在real中,调用api来获取主题)在该函数中,我迭代了topicData对象,将主题逐个传递给searchPage函数,并将其分配给
re
变量,以检查提供的主题是否与gmail收件箱消息中的文本匹配

这是我的密码

var topicData = [
    {
        id: 1,
        name: 'Courses'
    },
    {
        id: 2,
        name: 'miss'
    },
    {
        id: 3,
        name: 'out'
    },
    {
        id: 4,
        name: 'your'
    },
    {
        id: 5,
        name: 'savings'
    },
    {
        id: 6,
        name: 'and'
    }
];

function fetchTopics() {
    // const apiUrl = `http://localhost:3020/v2/emails`;
    // const headers = new Headers();
    // headers.append('Content-Type', 'application/json');
    return topicData.map(datum => {
        return searchPage(datum.name);
    });
    // fetch(apiUrl, {
    //  method: 'GET',
    //  headers
    // })
    //  .then(function(response) {
    //      return response.json();
    //  })
    //  .then(function(data) {
    //      topicData.map(datum => searchPage(data.name));
    //  })
    //  .catch(function(err) {
    //      console.log('err', err);
    //  });
}

/*  the searchPage function takes an argument which is going
to set the variable re. Then iterate through topic array and call the searchPage function
for each value inside it while passing that value to the function
*/
function searchPage(topic) {
    console.log('topic', topic);
    var re = new RegExp(topic, 'g'); // example regex that the function will use for search
    var regs;

    var walker = document.createTreeWalker(
        document.body,
        NodeFilter.SHOW_TEXT,
        function(node) {
            if ((regs = re.exec(node.textContent))) {
                if (!node.parentNode.classList.contains('highlighted_text')) {
                    var match = document.createElement('A');
                    match.appendChild(document.createTextNode(regs[0]));
                    match.href = `https://app.com/CustomTopic/${
                        regs[0]
                    }`;
                    match.classList.add('highlighted_text');

                    var after = node.splitText(regs.index);
                    after.nodeValue = after.nodeValue.substring(regs[0].length);
                    node.parentNode.insertBefore(match, after);
                }
            }
            return NodeFilter.FILTER_SKIP;
        },
        false
    );

    walker.nextNode();
}

// Run when the whole document loads
$(window).bind('load', function() {
    document.addEventListener('click', init);
    fetchTopics();
});

你能提供错误日志吗?不,我不知道错误,但是gmail被挂了。我必须关闭活动监视器。这里显示的是1.2gb内存,有时甚至更大。我这样做是否效率低下?