【问题标题】:Webkit showing Blank PageWebkit 显示空白页
【发布时间】:2014-01-07 10:30:40
【问题描述】:

我目前在 C# .net 中使用 WebKit。 在 WEBKIT 中加载此页面时遇到问题。 http://shop.orange.co.uk/mobile-phones/4g-ready-phoneshttp://www.vax.co.uk/ WEBKIT 成功显示其他网页内容 但在上述网页的情况下。有 一个空白网页。没有页面原创内容。 虽然此页面在 Firefox、Opera 浏览器中运行良好。 对此有何帮助? 感染这不是唯一的页面。 问候。

【问题讨论】:

    标签: c# browser webkit


    【解决方案1】:

    我发现无法使用 webkitdotnet 项目检查或调试 html/javascript。而且好像有一段时间没维护了。

    所以如果你有能力迁移到其他网络引擎,我会推荐CefSharp - Embedded Chromium for .NET。它是一个强大的引擎,我相信它拥有 webkitdotnet 的所有功能,它还允许附加 Chrome 浏览器检查器来调试页面。为此,您需要设置 RemoteDebuggingPort 属性:

    var settings = new CefSettings();
    settings.RemoteDebuggingPort = 8088;
    
    Cef.Initialize(settings);
    

    然后您可以在 Chrome 浏览器中打开 url http://localhost:8088 以附加在您的应用中运行的嵌入式引擎。

    CefSharp 项目的源代码包含 WinForms 和 WPF 应用程序的示例。您可以从这些示例轻松开始。

    更新:在编写时,CefSharp 组件不支持将整页快照作为图像。我在分支 https://github.com/ivan-sam/CefSharp 中创建了 ChromiumWebBrowserWithSnapshotSupport 类。我修改了 CefSharp.Wpf.Example 项目并添加了快照按钮,用于制作页面快照并打开图像。您也可以使用 ElementHost 将此控件放在 WinForms 表单上。

    如果您无法移动,我看到的唯一可用选项是在本地下载受影响的页面以及所有相关内容(脚本、css 等),然后使用本地 Web 服务器托管它。然后修改它以使用本文所述的Firebug Litehttp://habrahabr.ru/post/154917/ - 它是俄语):

    <!DOCTYPE html>
    <html>
    <head>
        ...
    
        <script type='text/javascript' src='/path/to/firebug-lite.js'>
        {
            overrideConsole: true,
            startInNewWindow: true,
            startOpened: true,
            enableTrace: true
        }
        </script>
    
        ...
    </head>
    <body>...</body>
    </html>
    

    要让 Firebug 在新窗口中打开,您应该添加以下 C# 代码:

    browser.Url = new Uri(
        "http://localhost/path/to/debug-version-of-interface.html",
        System.UriKind.Absolute);
    
    browser.NewWindowCreated += new NewWindowCreatedEventHandler(
    (sender, newWindowEventArgs) =>
    {
        // create new form with single item - Firebug Lite window
        debuggerForm = new DebuggerForm(newWindowEventArgs.WebKitBrowser);
        debuggerForm.Show();
    });
    

    Firebug lite 让您可以访问页面的 HTML DOM 和 JavaScript 控制台。

    调试愉快^)

    【讨论】:

    • 这是另一个不工作的网页.. www.vax.co.uk
    • 我怀疑早期的网页主题被网站管理员更改并显示结果为 webkitbrowsertest.exe 而 www.vax.co.uk 是了解问题的网站。
    • 似乎cef sharp 不会从网页生成图像。我想用cefsharp 生成网页的快照。
    • 您需要什么样的快照?如果它对页面的用户部分可见,即视口(正是您在控件中看到的),您可以使用 DrawToBitmap 方法(参见此处的示例maxivak.com/…)。示例引用 GeckoWebBrowser,但以相同的方式与 CefSharp 一起使用。如果您指的是整个页面的快照(也是不可见部分),请提供代码示例如何使用 WebKitDonNet 实现这一点(我只找到了这个 - stackoverflow.com/questions/13048213/…)。
    • tagRECT frameBounds = ((webFrameClass)((IWebView)wb.GetWebView()).mainFrame()).contentBounds(); int frameWidth = frameBounds.right - frameBounds.left; int frameHeight = frameBounds.bottom - frameBounds.top; //wb.Size = new Size(frameWidth, frameHeight ); wb.Size = new Size(frameWidth, (int)(frameHeight * 1.01)); wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height)); //其中 wb 是 webkit.net 浏览器
    猜你喜欢
    • 2014-07-19
    • 2015-06-06
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多