Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow backend to send commands to execute preamble scripts. #1122

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ extern "C" void V8RecordReplayFinishRecording();
extern "C" void V8RecordReplaySetCrashReason(const char* reason);
extern "C" char* V8RecordReplayReadAssetFileContents(const char* aPath, size_t* aLength);

static void RunScript(v8::Isolate* isolate, v8::Local<v8::Context> context, const char* source_raw, const char* filename);

static const char REPLAY_CDT_PAUSE_OBJECT_GROUP[] =
"REPLAY_CDT_PAUSE_OBJECT_GROUP";

Expand Down Expand Up @@ -825,7 +827,7 @@ const char* gOnNewWindowScript = R""""(
window.__RECORD_REPLAY__ = window.top.__RECORD_REPLAY__;
window.__RECORD_REPLAY_ARGUMENTS__ = window.top.__RECORD_REPLAY_ARGUMENTS__;

for (g of window.top.__RECORD_REPLAY_GLOBALS__) {
for (const g of window.top.__RECORD_REPLAY_GLOBALS__) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: My previous concern was not addressed -

  • We also need to pass down __RECORD_REPLAY_GLOBALS__ itself.
  • In fact, I'd vote to only pass down __RECORD_REPLAY_GLOBALS__, and just force any user of this API to go through that, rather than adding random globals into a global context that is shared with arbitrary user JS.

window[g] = window.top[g];
}
})()
Expand Down Expand Up @@ -2547,7 +2549,7 @@ static void InitializeRecordReplayApiObjects(v8::Isolate* isolate, LocalFrame* l
DefineProperty(isolate, context->Global(), "__RECORD_REPLAY_ARGUMENTS__",
args);

v8::Local<v8::Object> globals = v8::Object::New(isolate);
v8::Local<v8::Object> globals = v8::Map::New(isolate);
DefineProperty(isolate, context->Global(), "__RECORD_REPLAY_GLOBALS__",
Copy link

@Domiii Domiii Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will reset the globals on every root-level navigation. We probably want to keep them around or re-run the preamble.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was also confused about this. do we need to store the scripts somewhere so we can rerun them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domi and I have been chatting about our context handling, which is a tad naiive to say the least; we aren't going to worry about it in this PR, but rather address it wholly in another.

globals);

Expand Down