aboutsummaryrefslogtreecommitdiff
path: root/src/content/console-frames.js
blob: 0c0ec02ee1442ebef638a789d37ecd08d2d2476f (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
38
import './console-frame.scss';
import messages from 'shared/messages';

const initialize = (doc) => {
  let iframe = doc.createElement('iframe');
  iframe.src = browser.runtime.getURL('build/console.html');
  iframe.id = 'vimvixen-console-frame';
  iframe.className = 'vimvixen-console-frame';
  doc.body.append(iframe);

  return iframe;
};

const blur = (doc) => {
  let iframe = doc.getElementById('vimvixen-console-frame');
  iframe.blur();
};

const postMessage = (doc, message) => {
  let iframe = doc.getElementById('vimvixen-console-frame');
  iframe.contentWindow.postMessage(JSON.stringify(message), '*');
};

const postError = (doc, message) => {
  return postMessage(doc, {
    type: messages.CONSOLE_SHOW_ERROR,
    text: message,
  });
};

const postInfo = (doc, message) => {
  return postMessage(doc, {
    type: messages.CONSOLE_SHOW_INFO,
    text: message,
  });
};

export { initialize, blur, postError, postInfo };