mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
c6c71ef8f9
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`.
36 lines
926 B
JavaScript
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);
|