gpt4 book ai didi

delphi - 如何使用 dcef3 启用远程调试

转载 作者:行者123 更新时间:2023-12-02 03:47:51 25 4
gpt4 key购买 nike

我正在使用 dcef3 在我的 Delphi 应用程序中嵌入浏览器。我想启用远程调试,以便检查嵌入式浏览器中运行的 JavaScript 代码。

当显示包含 TChromium 控件的父窗体时,我尝试启用远程调试端口,但我不确定如何继续实际访问调试器:

procedure TMapViewSingleSector.FormShow(Sender: TObject);
begin
CefRemoteDebuggingPort := 9000;
ChromeView.Load('http://localhost:8080/');
end;

但是,当我尝试从另一个 Chrome 浏览器访问 localhost:9000 时,页面无法加载。

编辑:我将 CefRemoteDebuggingPort 初始化移至表单初始化部分(在表单显示之前)。现在,当我将 google chrome 指向端口 9000 时,我可以看到 Web 组件。但是我还有另一个错误:

inspector.js:10392 Uncaught TypeError: Object.observe is not a function
at WebInspector.Main._createSettings (inspector.js:10392)
at WebInspector.Main._gotPreferences (inspector.js:10384)
at WebInspector.InspectorFrontendHostStub.getPreferences (inspector.js:1352)
at WebInspector.Main._loaded (inspector.js:10383)
at windowLoaded (inspector.js:677)

注意:我的chrome浏览器版本与DCEF3不一样。

最佳答案

我只需从代码中打开开发人员工具控制台。有ShowDevTools方法来做到这一点。为此,您可以使用专用按钮或例如在 HTML 页面和 OnBeforeBrowse 中创建虚假链接事件取消导航并显示控制台。例如,当有这个假链接时:

<html>
<body>
<a href="ShowDevTools.fake">Show console</a>
</body>
</html>

您可以在应用程序中编写类似的内容:

procedure TForm1.Chromium1BeforeBrowse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
const
UrlShowDevTools = 'ShowDevTools.fake';
begin
{ if the user clicked link and URL equals to the fake one }
if (Request.TransitionType = TT_LINK) and (Request.Url = UrlShowDevTools) then
begin
{ cancel navigation }
Result := True;
{ show the developer tools console }
TChromium(Sender).ShowDevTools;
end;
end;

关于delphi - 如何使用 dcef3 启用远程调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44521330/

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