aboutsummaryrefslogtreecommitdiff
path: root/e2e/ambassador/src/content/index.js
blob: 0931f935ba83a584974a767b17e41dc367a405bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {
  WINDOWS_CREATE, WINDOWS_REMOVE, TABS_CREATE,
  EVENT_KEYPRESS, EVENT_KEYDOWN, EVENT_KEYUP,
} from '../shared/messages';
import * as ipc from './ipc';

ipc.receivePageMessage((message) => {
  switch (message.type) {
  case WINDOWS_CREATE:
  case WINDOWS_REMOVE:
  case TABS_CREATE:
  case EVENT_KEYPRESS:
  case EVENT_KEYDOWN:
  case EVENT_KEYUP:
    return ipc.sendToBackground(message);
  }
});

ipc.receiveBackgroundMesssage((message) => {
  switch (message.type) {
  case EVENT_KEYPRESS:
    document.body.dispatchEvent(
      new KeyboardEvent('keypress', { 'key': message.key }));
    break;
  case EVENT_KEYDOWN:
    document.body.dispatchEvent(
      new KeyboardEvent('keydown', { 'key': message.key }));
    break;
  case EVENT_KEYUP:
    document.body.dispatchEvent(
      new KeyboardEvent('keyup', { 'key': message.key }));
    break;
  }
  return Promise.resolve({});
});