Uncaught SyntaxError: Unexpected token ')' - 在 chrome 扩展文件中

问题描述

我正在尝试实现 chrome 扩展。我上传一个包含文件文件夹“扩展”-

  1. icon.png
  2. manifest.json
  3. popup.html
  4. popup.js
  5. style.css

chrome 扩展用于检测链接是否为钓鱼链接。扩展程序正确读取 URL,但当单击按钮提供结果时,它没有显示。在扩展选项卡中,它显示一条错误消息-

children

popup.js 的代码如下-

Uncaught SyntaxError: Unexpected token ')'

Context
popup.html
Stack Trace
popup.js:24 (anonymous function)

// alert(xhr.responseText);
        $("#div1").text(xhr.responseText);
        return xhr.responseText;
    });
} (This is what is highlighted as the error)

请帮助我理解错误是什么以及如何调试它以便结果显示在chrome扩展中。

以防万一,clientServer.PHP代码是-

// Purpose - This file contains all the logic relevant to the extension such as getting the URL,calling the server
// side clientServer.PHP which then calls the core logic.

function transfer(){    
    var tablink;
    chrome.tabs.getSelected(null,function(tab) {
        tablink = tab.url;
        $("#p1").text("The URL being tested is - "+tablink);

        var xhr=new XMLHttpRequest();
        params="url="+tablink;
        // alert(params);
        var markup = "url="+tablink+"&html="+document.documentElement.innerHTML;
        xhr.open("GET","clientServer.PHP",true);
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr.send(markup);

        
        // Uncomment this line if you see some error on the extension to see the full error message for debugging.
        // alert(xhr.responseText);
        $("#div1").text(xhr.responseText);
        return xhr.responseText;
    });
}


$(document).ready(function(){
    $("button").click(function(){   
        var val = transfer();
    });
});

// chrome.tabs.getSelected(null,function(tab) {
//      var tablink = tab.url;
//  $("#p1").text("The URL being tested is - "+tablink);
// });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)