python - 如何在 CefPython 中启用外部文件链接?
问题描述
我正在开发一个 CEFPython 应用程序,该应用程序需要我包含一些外部文件,例如 JS 或 CSS 库。但是 HTML 文件中提到的任何外部路径(指同一文件夹中存在的外部库和在线资源 URL)似乎是不可接受,我确定缺少一个启用外部文件喜欢的标志,但无法弄清楚是哪个。下面是我的主要功能的代码:
def main():
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
# To change user agent use either "product_version"
# or "user_agent" options. Explained in Tutorial in
# "Change user agent string" section.
settings = {
# "web_security_disabled": True,
# "user_agent": "MyAgent/20.00 MyProduct/10.00",
}
cef.Initialize(settings=settings)
browser = cef.CreateBrowserSync(url=html_to_data_uri(HTML_code),
window_title="Demo Program")
set_javascript_bindings(browser)
cef.MessageLoop()
cef.Shutdown()
解决方案
“web_security_disabled”设置必须在浏览器创建中传递,而不是在 cef 初始化中传递。
例子 :
settings = {
"web_security_disabled": True,
}
def launcher(url):
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url=url, window_title="my title", settings=settings)
cef.MessageLoop()
cef.Shutdown()
推荐阅读
- angular - 由于某种原因没有出现 Angular 对话框窗口
- dart - 我们在flutter的dev_dependencies下添加的
- c# - 我们如何在 foreach 循环中将行分成 3 列
- android - 在 gradle 中添加 kapt androidx room 会导致数据绑定错误
- angular - Angular 工作区库 - 调试错误:无法解决条目构建错误
- c# - 我收到此错误无法将字符串隐式转换为 system.data.datatable
- c++ - How can I write a better and cleaner version of my bank account code?
- c++ - Getting errors trying to pass a vector to a class's function C++
- python - Python:每组多个统计信息
- javascript - 电脑与手机的区别