0

I made a Chrome extension which overrides 'New Tab' page. On the page, I created a clickable icon. I want to click and 'Task Manager' window to appear. Though I overridden the click-event handler (by simulating a keyboard event using KeyboardEvent() constructor) associated to that icon, nothing happens. This is the code:

event1=new KeyboardEvent('keypress',{
    bubbles:true,
    cancelable:true,
    shiftKey:true,
    code:'Escape',
    key:'Escape'
    });
window.dispatchEvent(event1);
return false; //Shift+Escape is Chrome shortcut for Task Manager

What am I doing wrong? I'd rather use Javascript.

Luca Putzu
  • 1,438
  • 18
  • 24
Black Sun
  • 27
  • 4
  • 1
    I believe JS events only have effect on the page itself, rather than the surrounding browser. I've never heard of any browser function being triggered for which there wasn't a specific API. – sg.cc Feb 09 '16 at 21:42

1 Answers1

3

The chrome task manager being such a low-level feature, I'd be surprised if you can invoke it by faking a keypress event even from the extension code. Key presses are filtered on the way down .. through the extensions and eventually to pages. This particular keypress is probably always intercepted at the highest level. It'd probably be undesirable to allow an extension or a page to know that the event occurred and it would certainly be undesirable to allow it to be intercepted. So I would think that Chrome isn't listening for the event to bubble back up before it invokes the window - it just does it and doesn't forward or listen for it bubbling.

Instead you'd need to ask Google for a special API call for the extension to call, proxied by the extension from any page code (if necessary). There doesn't seem to be an "chrome://tasks" even.

Jason Kleban
  • 20,024
  • 18
  • 75
  • 125