gpt4 book ai didi

javascript - CEFSharp RegisterExtension 不起作用

转载 作者:行者123 更新时间:2023-12-03 04:34:31 27 4
gpt4 key购买 nike

我有一个使用 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';
};
})();

扩展的语法是否发生了变化?

最佳答案

https://bugs.chromium.org/p/chromium/issues/detail?id=665391

这是 Chrome 的问题,看起来他们不会修复它。

关于javascript - CEFSharp RegisterExtension 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43353445/

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