Javascript CEFSharp注册表扩展不工作

Javascript CEFSharp注册表扩展不工作,javascript,c#,chromium-embedded,cefsharp,Javascript,C#,Chromium Embedded,Cefsharp,我有一个screen scraper应用程序,使用了CEFSharp,在我将CEFSharp更新到最新版本之前,该应用程序运行良好。看来我注册javascript扩展函数的方式不再有效了。这是我的启动代码: [STAThread] public static void Main() { try { CefSettings settings = new CefSettings(); settings.RegisterExtension(new Ce

我有一个screen scraper应用程序,使用了CEFSharp,在我将CEFSharp更新到最新版本之前,该应用程序运行良好。看来我注册javascript扩展函数的方式不再有效了。这是我的启动代码:

[STAThread]
public static void Main()
{
    try
    {
        CefSettings settings = new CefSettings();

        settings.RegisterExtension(new CefExtension("showModalDialog", Resources.showModalDialog));

        //Perform dependency check to make sure all relevant resources are in our output directory.
        Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);

        ProcessCommandLine();

        var browser = new BrowserForm("https://www.google.com");

        Application.Run(browser);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}
如果我注释掉settings.RegisterExtension行,它运行正常。它过去是有用的。以下是我的分机代码:

(function () {
    absolutePath = function (href) {
        var link = document.createElement("a");
        link.href = href;
        return (link.protocol + "//" + link.host + link.pathname + link.search + link.hash);
    }
    showModalDialog = function (url, arg, opt) {
        url = url || ''; //URL of a dialog
        arg = arg || null; //arguments to a dialog
        opt = opt || 'dialogWidth:300px;dialogHeight:200px'; //options: dialogTop;dialogLeft;dialogWidth;dialogHeight or CSS styles
        var caller = showModalDialog.caller.toString();
        var dialog = document.body.appendChild(document.createElement('dialog'));
        dialog.setAttribute('style', opt.replace(/dialog/gi, ''));
        dialog.innerHTML = '<a href="#" id="dialog-close" style="position: absolute; top: 0; right: 4px; font-size: 20px; color: #000; text-decoration: none; outline: none;">&times;</a><iframe id="dialog-body" name="dialog-body" src="' + absolutePath(url) + '" style="border: 0; width: 100%; height: 100%;"></iframe>';
        //document.getElementById('dialog-body').contentWindow.dialogArguments = arg;
        document.getElementById('dialog-close').addEventListener('click', function (e) {
            e.preventDefault();
            dialog.close();
        });
        document.getElementById('dialog-body').addEventListener('load',     function (e) {
            this.style.height = this.contentWindow.document.body.scrollHeight + 'px';
            this.style.width = this.contentWindow.document.body.scrollWidth + 'px';
            this.contentWindow.close = function () {
                dialog.close();
            };
            this.contentWindow.dialogArguments = arg;
            this.window = this.contentWindow;
        });

        dialog.showModal();
        //if using yield
        if (caller.indexOf('yield') >= 0) {
            return new Promise(function (resolve, reject) {
                dialog.addEventListener('close', function () {
                    var returnValue = document.getElementById('dialog-    body').contentWindow.returnValue;
                    document.body.removeChild(dialog);
                    resolve(returnValue);
                });
            });
        }
        //if using eval
        var isNext = false;
        var nextStmts = caller.split('\n').filter(function (stmt) {
            if (isNext || stmt.indexOf('showModalDialog(') >= 0)
                return isNext = true;
            return false;
        });

        dialog.addEventListener('close', function () {
            var returnValue = document.getElementById('dialog-body').contentWindow.returnValue;
            document.body.removeChild(dialog);
            //nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\(.*\)/g, JSON.stringify(returnValue));
            //eval('{\n' + nextStmts.join('\n'));
        });
        throw 'Execution stopped until showModalDialog is closed';
    };
})();
扩展的语法有什么变化吗


这是一个Chrome的东西,看起来他们不会去修复它。

为什么会投反对票?什么版本?您需要在CEF项目中记录一个bug。作为一种解决方法,定义一个对象,并使用该对象定义您的函数。我可以注册一个bug报告。我会把版本信息放在那里。我不是java专家,但是如果我把函数放在一个对象中,我必须用对象名限定函数调用。尽管ShowModalDialog已经过时,但我正在抓取的网站使用它,网页将其作为本机函数调用,因此除非您知道一个巧妙的技巧,否则我需要本机提供该函数。您可以在OnContextCreated中执行JavaScript来注入代码。有关更多信息,请参阅通用使用指南。我已经捕获了OnContextCreated事件,但似乎没有实现CEFRegisterExtension。我有一个resource.js文件,里面有我的脚本。您能告诉我使用哪个命令将其插入页面吗?很抱歉这么密集,但我不太会写javascript,我只知道足够让它工作,然后在它再次崩溃之前我不会碰它。通常几年。。。