aboutsummaryrefslogtreecommitdiff
path: root/e2e/ambassador/src/content/index.js
blob: 8573d66e782455685b2d950964e8c75ae0d56b74 (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
36
37
import {
  WINDOWS_CREATE, WINDOWS_REMOVE, WINDOWS_GET,
  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 WINDOWS_GET:
  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({});
});