Files
react/shells/dev/src/backend.js
T
Ivan Babak c6c71ef8f9 Fix profiling screenshots data structure to map rootID to commitIndex
Propagate `rootID` throughout the code for `captureScreenshot`.

Rename private profiling maps of `store` to make relations more clear.

Fix missing cleanup for screenshots data in `set importedProfilingData` of `store`.
2019-05-01 01:07:36 -07:00

36 lines
926 B
JavaScript

/** @flow */
import html2canvas from 'html2canvas';
import Agent from 'src/backend/agent';
import Bridge from 'src/bridge';
import { initBackend } from 'src/backend';
const bridge = new Bridge({
listen(fn) {
const listener = event => {
fn(event.data);
};
window.addEventListener('message', listener);
return () => {
window.removeEventListener('message', listener);
};
},
send(event: string, payload: any, transferable?: Array<any>) {
window.parent.postMessage({ event, payload }, '*', transferable);
},
});
bridge.addListener('captureScreenshot', ({ commitIndex, rootID }) => {
html2canvas(document.body, { logging: false }).then(canvas => {
bridge.send('screenshotCaptured', {
commitIndex,
dataURL: canvas.toDataURL(),
rootID,
});
});
});
const agent = new Agent(bridge);
initBackend(window.__REACT_DEVTOOLS_GLOBAL_HOOK__, agent, window.parent);