开发者

press Ctrl+Shift+Del outof firefox extension

开发者 https://www.devze.com 2022-12-15 03:23 出处:网络
So, i need to press Ctrl+Shift+Del in a program way. I want my extension to press Ctrl+Shift+Del and then press Enter

So, i need to press Ctrl+Shift+Del in a program way. I want my extension to press Ctrl+Shift+Del and then press Enter (to clean all history,cookies,cache and so on). i do next:

var e=document.createEvent('KeyboardEvent');
e.initKeyEvent( 'keypr开发者_高级运维ess', true, true, window, true, false, true, false, 46, 0);
document.dispatchEvent(e);

According to how i understand, this code has to emulate pressing Ctrl+Shift+Del but nothing happens...document.dispatchEvent(e) happens but the window that is called by pressing Ctrl+Shift+Del doesn't appear. Why?

p.s.I know about Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager).removeAll(); but it's not suitable in my situashion. i do definetly need to "press" the combination Ctrl+Shift+Del so..any ideas? see mistakes?


Emulating key press events to start a native function of the browser sounds like a bad, and probably unnecessary, idea.

Why not check out other extensions that clear the cache/history like this one and check out its source code to see how it's done.


How about opening the popup that Ctrl+Shift+Del opens?

Edit: It's chrome://browser/content/sanitize.xul. You may also want to have a look at chrome://browser/content/sanitize.js.

0

精彩评论

暂无评论...
验证码 换一张
取 消