mirror of https://github.com/jumpserver/jumpserver
perf: chrome 添加插件
parent
bcb4e04200
commit
cc2e42c77a
|
@ -186,9 +186,9 @@ class WebAPP(object):
|
|||
|
||||
def default_chrome_driver_options():
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("start-maximized")
|
||||
# 禁用 扩展
|
||||
options.add_argument("--disable-extensions")
|
||||
options.add_argument("--start-maximized")
|
||||
options.add_argument("--new-window")
|
||||
|
||||
# 忽略证书错误相关
|
||||
options.add_argument('--ignore-ssl-errors')
|
||||
options.add_argument('--ignore-certificate-errors')
|
||||
|
@ -215,6 +215,7 @@ class AppletApplication(BaseApplication):
|
|||
self.app = WebAPP(app_name=self.app_name, user=self.user,
|
||||
account=self.account, asset=self.asset, platform=self.platform)
|
||||
self._chrome_options = default_chrome_driver_options()
|
||||
self._chrome_options.add_argument("--app={}".format(self.asset.address))
|
||||
|
||||
def run(self):
|
||||
service = Service()
|
||||
|
@ -223,7 +224,6 @@ class AppletApplication(BaseApplication):
|
|||
self.driver = webdriver.Chrome(options=self._chrome_options, service=service)
|
||||
self.driver.implicitly_wait(10)
|
||||
if self.app.asset.address != "":
|
||||
self.driver.get(self.app.asset.address)
|
||||
ok = self.app.execute(self.driver)
|
||||
if not ok:
|
||||
print("执行失败")
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// background.js
|
||||
|
||||
// 监听标签页的创建事件
|
||||
chrome.tabs.onCreated.addListener(function (tab) {
|
||||
// 获取当前窗口的所有标签页
|
||||
chrome.tabs.query({currentWindow: true}, function (tabs) {
|
||||
// 如果当前窗口的标签页数量大于1,则关闭新创建的标签页
|
||||
if (tabs.length > 1) {
|
||||
chrome.tabs.remove(tab.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener("contextmenu", function (event) {
|
||||
event.preventDefault();
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// content_script.js
|
||||
|
||||
// 获取所有的 <a> 标签元素
|
||||
const links = document.getElementsByTagName('a');
|
||||
|
||||
// 遍历 <a> 标签元素并修改链接属性
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
links[i].target = '_self'; // 将 target 属性设置为 _self,当前窗口打开
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener(
|
||||
function (request, sender, sendResponse) {
|
||||
$("iframe").attr("src", request.url);
|
||||
sendResponse({farewell: "goodbye"});
|
||||
}
|
||||
)
|
||||
|
||||
document.addEventListener("contextmenu", function (event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "禁止新标签窗口菜单",
|
||||
"version": "1.0",
|
||||
"description": "将所有链接替换为当前窗口打开, 并禁止新窗口和标签,隐藏右击菜单",
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
],
|
||||
"persistent": false
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"*://*/*"
|
||||
],
|
||||
"js": [
|
||||
"content_script.js"
|
||||
],
|
||||
"run_at": "document_end"
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
"tabs"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue