This repository has been archived on 2023-09-06. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
py-gtk-notes
Archived
1
0
Fork 0
py-gtk-notes/notes/webkit-settings.py

48 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import gi
gi.require_version("Gtk", "3.0")
gi.require_version("WebKit2", "4.1")
from gi.repository import Gtk, WebKit2
settings = WebKit2.Settings()
settings.set_enable_page_cache(True)
settings.set_enable_offline_web_application_cache(True)
settings.set_javascript_can_access_clipboard(True)
settings.set_javascript_can_open_windows_automatically(True)
settings.set_user_agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) weapp/1.0.0 Version/16.4 Safari/605.1.15")
# indexedDB 和 localStorage 和 离线缓存
settings.set_enable_html5_database(True)
settings.set_enable_html5_local_storage(True)
settings.set_enable_offline_web_application_cache(True)
# 平滑滚动
settings.set_enable_smooth_scrolling(True)
settings.set_enable_fullscreen(True)
# 媒体播放是否需要 用户主动行为
settings.set_media_playback_requires_user_gesture(False)
# 允许视频播放窗口不强制全屏
settings.set_media_playback_allows_inline(True)
# 关闭之后, 可以随便跨域请求, 但是有安全隐患(不过, 只要保证你页面只运行你自己的代码, 及信任的代码, 就不会有任何问题)
settings.set_disable_web_security(True)
# 允许开发者控制台
settings.set_enable_developer_extras(True)
# 是用于启用或禁用模拟捕获设备的设置选项。
# 在开发网页应用程序时,经常需要使用摄像头或麦克风等捕获设备进行测试和调试。但是,在某些情况下,可能无法直接访问实际的物理捕获设备,或者不希望在开发过程中实际使用这些设备。
# 通过启用WebKit2.Settings:enable-mock-capture-devices设置选项可以使用虚拟的模拟捕获设备来替代实际的物理设备。这样开发人员可以在没有真实设备的情况下进行捕获设备相关的功能测试和调试提高开发效率并简化开发流程。
settings.set_enable_mock_capture_devices(True)
python + gtk3 + webkit2 学习笔记
Python 60.1%
JavaScript 37.6%
HTML 2.3%