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

时间:2021-02-07 06:24:43

标签: javascript php google-chrome-extension popup jason

我正在尝试实现 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);
// });

0 个答案:

没有答案