Compare commits

...

1 Commits

Author SHA1 Message Date
Shelley Vohr
90f1c37a78 fix: InspectorFrontendHost override in embedded windows 2026-02-17 15:20:40 +01:00
3 changed files with 29 additions and 17 deletions

View File

@@ -23,6 +23,9 @@ export default contextBridge;
export const internalContextBridge = {
contextIsolationEnabled: process.contextIsolated,
tryOverrideGlobalValueFromIsolatedWorld: (keys: string[], value: any) => {
return binding._overrideGlobalValueFromIsolatedWorld(keys, value, true, true);
},
overrideGlobalValueFromIsolatedWorld: (keys: string[], value: any) => {
return binding._overrideGlobalValueFromIsolatedWorld(keys, value, false);
},

View File

@@ -11,14 +11,12 @@ const { contextIsolationEnabled } = internalContextBridge;
* 1) Use menu API to show context menu.
*/
window.onload = function () {
if (window.InspectorFrontendHost) {
if (contextIsolationEnabled) {
internalContextBridge.overrideGlobalValueFromIsolatedWorld([
'InspectorFrontendHost', 'showContextMenuAtPoint'
], createMenu);
} else {
window.InspectorFrontendHost.showContextMenuAtPoint = createMenu;
}
if (contextIsolationEnabled) {
internalContextBridge.tryOverrideGlobalValueFromIsolatedWorld([
'InspectorFrontendHost', 'showContextMenuAtPoint'
], createMenu);
} else {
window.InspectorFrontendHost!.showContextMenuAtPoint = createMenu;
}
};

View File

@@ -5,6 +5,7 @@
#include "shell/renderer/api/electron_api_context_bridge.h"
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
@@ -826,13 +827,18 @@ void ExposeAPIInWorld(v8::Isolate* isolate,
ExposeAPI(isolate, source_context, target_isolate, target_context, key, api);
}
gin_helper::Dictionary TraceKeyPath(const gin_helper::Dictionary& start,
const std::vector<std::string>& key_path) {
std::optional<gin_helper::Dictionary> TraceKeyPath(
const gin_helper::Dictionary& start,
const std::vector<std::string>& key_path,
bool allow_silent_failure) {
gin_helper::Dictionary current = start;
for (size_t i = 0; i < key_path.size() - 1; i++) {
CHECK(current.Get(key_path[i], &current))
<< "Failed to get property '" << key_path[i] << "' at index " << i
<< " in key path";
if (!current.Get(key_path[i], &current)) {
if (allow_silent_failure)
return std::nullopt;
CHECK(false) << "Failed to get property '" << key_path[i] << "' at index "
<< i << " in key path";
}
}
return current;
}
@@ -841,7 +847,8 @@ void OverrideGlobalValueFromIsolatedWorld(
v8::Isolate* isolate,
const std::vector<std::string>& key_path,
v8::Local<v8::Object> value,
bool support_dynamic_properties) {
bool support_dynamic_properties,
bool allow_silent_failure) {
if (key_path.empty())
return;
@@ -853,7 +860,11 @@ void OverrideGlobalValueFromIsolatedWorld(
gin_helper::Dictionary global(isolate, main_context->Global());
const std::string final_key = key_path[key_path.size() - 1];
gin_helper::Dictionary target_object = TraceKeyPath(global, key_path);
auto maybe_target_object =
TraceKeyPath(global, key_path, allow_silent_failure);
if (!maybe_target_object.has_value())
return;
gin_helper::Dictionary target_object = maybe_target_object.value();
{
v8::Context::Scope main_context_scope(main_context);
@@ -886,8 +897,8 @@ bool OverrideGlobalPropertyFromIsolatedWorld(
gin_helper::Dictionary global(isolate, main_context->Global());
const std::string final_key = key_path[key_path.size() - 1];
v8::Local<v8::Object> target_object =
TraceKeyPath(global, key_path).GetHandle();
auto target_dict = TraceKeyPath(global, key_path, false);
v8::Local<v8::Object> target_object = target_dict.value().GetHandle();
{
v8::Context::Scope main_context_scope(main_context);