evalInInspectedWindow.js — react Source File
Architecture documentation for evalInInspectedWindow.js, a javascript file in the react codebase. 1 imports, 4 dependents.
Entity Profile
Dependency Diagram
graph LR 5da5ec89_70b9_80cd_1b31_dcf27eddc57e["evalInInspectedWindow.js"] 3ed4f770_e0fe_be1b_53aa_15b5121435ea["evalScripts.js"] 5da5ec89_70b9_80cd_1b31_dcf27eddc57e --> 3ed4f770_e0fe_be1b_53aa_15b5121435ea 4f973625_4ea3_727f_a21d_315a6a251079["elementSelection.js"] 4f973625_4ea3_727f_a21d_315a6a251079 --> 5da5ec89_70b9_80cd_1b31_dcf27eddc57e b5e42467_7633_e234_1d51_a93bfc4818c7["index.js"] b5e42467_7633_e234_1d51_a93bfc4818c7 --> 5da5ec89_70b9_80cd_1b31_dcf27eddc57e 8351037d_1dab_1acd_e2b9_a54883052fb1["reactPolling.js"] 8351037d_1dab_1acd_e2b9_a54883052fb1 --> 5da5ec89_70b9_80cd_1b31_dcf27eddc57e 96cefe22_9962_3835_9c5b_31bab845839c["sourceSelection.js"] 96cefe22_9962_3835_9c5b_31bab845839c --> 5da5ec89_70b9_80cd_1b31_dcf27eddc57e style 5da5ec89_70b9_80cd_1b31_dcf27eddc57e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {EvalScriptIds} from '../evalScripts';
import {evalScripts} from '../evalScripts';
type ExceptionInfo = {
code: ?string,
description: ?string,
isError: boolean,
isException: boolean,
value: any,
};
const EVAL_TIMEOUT = 1000 * 10;
let evalRequestId = 0;
const evalRequestCallbacks = new Map<
number,
(value: {result: any, error: any}) => void,
>();
function fallbackEvalInInspectedWindow(
scriptId: EvalScriptIds,
args: any[],
callback: (value: any, exceptionInfo: ?ExceptionInfo) => void,
) {
if (!evalScripts[scriptId]) {
throw new Error(`No eval script with id "${scriptId}" exists.`);
}
const code = evalScripts[scriptId].code.apply(null, args);
const tabId = chrome.devtools.inspectedWindow.tabId;
const requestId = evalRequestId++;
chrome.runtime.sendMessage({
source: 'devtools-page',
payload: {
type: 'eval-in-inspected-window',
tabId,
requestId,
scriptId,
args,
},
});
const timeout = setTimeout(() => {
evalRequestCallbacks.delete(requestId);
if (callback) {
callback(null, {
code,
description:
'Timed out while waiting for eval response from the inspected window.',
isError: true,
isException: false,
value: undefined,
});
}
}, EVAL_TIMEOUT);
evalRequestCallbacks.set(requestId, ({result, error}) => {
clearTimeout(timeout);
evalRequestCallbacks.delete(requestId);
if (callback) {
if (error) {
callback(null, {
code,
description: undefined,
isError: false,
isException: true,
value: error,
});
return;
}
callback(result, null);
}
});
}
export function evalInInspectedWindow(
scriptId: EvalScriptIds,
args: any[],
callback: (value: any, exceptionInfo: ?ExceptionInfo) => void,
) {
if (!evalScripts[scriptId]) {
throw new Error(`No eval script with id "${scriptId}" exists.`);
}
const code = evalScripts[scriptId].code.apply(null, args);
chrome.devtools.inspectedWindow.eval(code, (result, exceptionInfo) => {
if (!exceptionInfo) {
callback(result, exceptionInfo);
return;
}
// If an exception (e.g. CSP Blocked) occurred,
// fallback to the content script eval context
fallbackEvalInInspectedWindow(scriptId, args, callback);
});
}
chrome.runtime.onMessage.addListener(({payload, source}) => {
if (source === 'react-devtools-background') {
switch (payload?.type) {
case 'eval-in-inspected-window-response': {
const {requestId, result, error} = payload;
const callback = evalRequestCallbacks.get(requestId);
if (callback) {
callback({result, error});
}
break;
}
}
}
});
Domain
Subdomains
Functions
Dependencies
Imported By
Source
Frequently Asked Questions
What does evalInInspectedWindow.js do?
evalInInspectedWindow.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in evalInInspectedWindow.js?
evalInInspectedWindow.js defines 1 function(s): fallbackEvalInInspectedWindow.
What does evalInInspectedWindow.js depend on?
evalInInspectedWindow.js imports 1 module(s): evalScripts.js.
What files import evalInInspectedWindow.js?
evalInInspectedWindow.js is imported by 4 file(s): elementSelection.js, index.js, reactPolling.js, sourceSelection.js.
Where is evalInInspectedWindow.js in the architecture?
evalInInspectedWindow.js is located at packages/react-devtools-extensions/src/main/evalInInspectedWindow.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-extensions/src/main).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free