gpt4 book ai didi

javascript - 如何从控制台将 LightTable 动态连接到外部浏览器?

转载 作者:行者123 更新时间:2023-11-27 23:36:32 25 4
gpt4 key购买 nike

我想尝试一些新的 ECMAScript 功能,但与 LightTable 集成的浏览器没有这些功能。为此,我需要连接到外部浏览器,并且 LightTable 需要此行:

<script type='text/javascript' id='lt_ws' src='http://localhost:53742/socket.io/lighttable/ws.js'></script>

我尝试过:

document.head.innerHTML+="<script type='text/javascript' id='lt_ws' src='http://localhost:53742/socket.io/lighttable/ws.js'></script>"

但 LightTable 仍然看不到连接:

"No client available. We don't know what kind of client you want for this one. Try starting a client by choosing one of the connection types in the connect panel."

如何将其更改为可粘贴到控制台选项卡中的 JavaScript 代码,以便我从控制台将 LightTable 动态连接到外部浏览器?

最佳答案

感谢Bergi在评论中指出 innerHTML 不起作用,我必须使用 DOM 方法。将以下代码粘贴到控制台中,将 LightTable 与浏览器连接起来。

该脚本将需要并询问端口和 because this changes and every window uses a port这需要手动插入。

查看需要引入什么端口:按 Ctrl + 空格,键入 connect,然后选择连接到浏览器。您将看到该端口显示在 HTML 代码段的 URL 中。

var port = prompt("What's the port number?");   
var script_tag = document.createElement("script");
script_tag.setAttribute("src", "http://localhost:"+port+"/socket.io/lighttable/ws.js");
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("id", "lt_ws");
document.head.appendChild(script_tag);

此外,这也可以用作书签:

javascript:(function()%7Bvar port %3D prompt("What's the port number%3F")%3Bvar script_tag %3D document.createElement("script")%3Bscript_tag.setAttribute("src"%2C "http%3A%2F%2Flocalhost%3A"%2Bport%2B"%2Fsocket.io%2Flighttable%2Fws.js")%3Bscript_tag.setAttribute("type"%2C "text%2Fjavascript")%3Bscript_tag.setAttribute("id"%2C "lt_ws")%3Bdocument.head.appendChild(script_tag)%7D)()

这种方法的优点是您可以在已加载的实时页面上使用 LightTable 连接并尝试或调试。

关于javascript - 如何从控制台将 LightTable 动态连接到外部浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34091219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com