diff --git a/docs/api/context-bridge.md b/docs/api/context-bridge.md index 4c63e411ef40..6eb7dd2a2bcc 100644 --- a/docs/api/context-bridge.md +++ b/docs/api/context-bridge.md @@ -157,6 +157,7 @@ has been included below for completeness: | [Cloneable Types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) | Simple | ✅ | ✅ | See the linked document on cloneable types | | `Element` | Complex | ✅ | ✅ | Prototype modifications are dropped. Sending custom elements will not work. | | `Blob` | Complex | ✅ | ✅ | N/A | +| `VideoFrame` | Complex | ✅ | ✅ | N/A | | `Symbol` | N/A | ❌ | ❌ | Symbols cannot be copied across contexts so they are dropped | If the type you care about is not in the above table, it is probably not supported. diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 10a87a4f0463..e12b5c992ff3 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -28,7 +28,9 @@ #include "third_party/blink/public/web/web_blob.h" #include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_local_frame.h" +#include "third_party/blink/renderer/bindings/modules/v8/v8_video_frame.h" // nogncheck #include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck +#include "third_party/blink/renderer/modules/webcodecs/video_frame.h" // nogncheck namespace features { BASE_FEATURE(kContextBridgeMutability, @@ -414,6 +416,17 @@ v8::MaybeLocal PassValueToOtherContextInner( v8::Context::Scope destination_context_scope(destination_context); return v8::MaybeLocal(blob.ToV8Value(destination_isolate)); } + + // Custom logic to "clone" VideoFrame references + blink::VideoFrame* video_frame = + blink::V8VideoFrame::ToWrappable(source_context->GetIsolate(), value); + if (video_frame != nullptr) { + blink::ScriptState* script_state = blink::ScriptState::ForCurrentRealm( + destination_context->GetIsolate()); + return v8::MaybeLocal( + blink::ToV8Traits::ToV8(script_state, + video_frame)); + } } // Proxy all objects