![](/img/trans.png)
[英]Is there a keyboard shortcut to toggle/show Inspector in React Native?
[英]Keyboard shortcut to Toggle (hide/show) my chrome extension
我正在開發擴展程序,我希望我的chrome擴展程序通過命令說(mac:“ CMD + SHIFT + 9”或默認:“ Ctrl + Shift + 9”)來切換(顯示/隱藏); 雖然我在清單文件中定義了命令:
{
.........
"commands": {
"toggle-window": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
},
"description": "Toggle feature foo",
"global": true
},
........
}
現在,我可以在backgroundScript.js中做什么呢?
我的backgroundScript.js是:
chrome.commands.onCommand.addListener(function(command) {
if(command === "toggle-window") {
console.log('Command:', command);
/* Logic to show/hide will go here..*/
}
});
我該怎么做? 謝謝!
實現了此“顯示/隱藏”功能的示例擴展演示:
https://chrome.google.com/webstore/detail/meldium-browser-extension/fdocegmnehjgfhfjelhmaobjccoiklle
經過長時間的研究,我終於把它解決了。首先,感謝@CViejo,他給了我這個問題的提示:
“只要在清單文件中使用“ _execute_browser_action”而不是“ toggle-window”,Chrome就會為您處理此功能。
我像@CViejo這樣更新了manifest.js文件:
{
.........
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
}
}
........
}
然后,我重新加載了我的擴展程序,但是它仍然沒有用..然后我只是在擴展程序頁面底部找到了鍵盤快捷方式框,我在網上閱讀了該信息,它基本上可以幫助我們“驗證建議的鍵是否確實在那里設置了在清單文件中定義的“鍵盤快捷方式”框中。 我選中了鍵盤快捷鍵框,即使該鍵可用並已在清單中定義,也未設置該鍵。
然后從堆棧溢出中,我發現了這個(那是主要錯誤): https : //stackoverflow.com/a/25654514/5228251
如您在此處的源代碼中所見: https : //code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package : chromium&rcl= 1409677023
僅在觸發OnExtensionWillBeInstalled回調時才運行鍵綁定更新。
因此,您需要卸載並重新安裝本地擴展,才能看到默認鍵盤命令出現在:chrome:// extensions / configureCommands
我只是卸載了重新安裝的解壓縮擴展程序,並檢查了默認鍵盤命令是否出現在chrome:// extensions / configureCommands中
它開始在我的擴展程序中起作用...
非常感謝@CViejo和@Stephane Brillant ...
願這也能幫助其他人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.