Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Created November 13, 2020 17:56
Show Gist options
  • Select an option

  • Save jasonLaster/7e94b8194f506b0986b34b1468531ab6 to your computer and use it in GitHub Desktop.

Select an option

Save jasonLaster/7e94b8194f506b0986b34b1468531ab6 to your computer and use it in GitHub Desktop.
diff --git a/devtools/server/actors/replay/connection.js b/devtools/server/actors/replay/connection.js
index 10653c994a11..64f81c8cff9e 100644
--- a/devtools/server/actors/replay/connection.js
+++ b/devtools/server/actors/replay/connection.js
@@ -10,7 +10,9 @@ const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
-const { setTimeout } = Components.utils.import('resource://gre/modules/Timer.jsm');
+const { setTimeout } = Components.utils.import(
+ "resource://gre/modules/Timer.jsm"
+);
XPCOMUtils.defineLazyModuleGetters(this, {
AppUpdater: "resource:///modules/AppUpdater.jsm",
@@ -142,11 +144,11 @@ const gRecordings = new Map();
let gNextMessageId = 1;
-function sendCommand(channelId, method, params) {
+function sendCommand(method, params) {
const id = gNextMessageId++;
gWorker.postMessage({
kind: "sendCommand",
- id: channelId,
+ id: gMainChannelId,
command: { id, method, params },
});
return waitForCommandResult(id);
@@ -180,11 +182,11 @@ async function addRecordingResource(recordingId, url) {
const text = await response.text();
const resource = getResourceInfo(url, text);
- await sendCommand(
- gMainChannelId,
- "Internal.addRecordingResource",
- { recordingId, resource }
- );
+ // getLoggedInUser
+ await sendCommand("Internal.addRecordingResource", {
+ recordingId,
+ resource,
+ });
const { known } = await sendCommand(
gMainChannelId,
@@ -192,11 +194,10 @@ async function addRecordingResource(recordingId, url) {
{ resource }
);
if (!known) {
- await sendCommand(
- gMainChannelId,
- "Internal.addResource",
- { resource, contents: text }
- );
+ await sendCommand("Internal.addResource", {
+ resource,
+ contents: text,
+ });
}
return text;
@@ -254,4 +255,4 @@ function onCommandResult(id, result) {
}
// eslint-disable-next-line no-unused-vars
-var EXPORTED_SYMBOLS = ["Initialize"];
+var EXPORTED_SYMBOLS = ["Initialize", "sendCommand"];
diff --git a/devtools/server/actors/replay/module.js b/devtools/server/actors/replay/module.js
index 161f3ae6ffba..23b43553e8b5 100644
--- a/devtools/server/actors/replay/module.js
+++ b/devtools/server/actors/replay/module.js
@@ -249,11 +249,14 @@ gDebugger.onNewScript = (script) => {
const recordingId = RecordReplayControl.recordingId();
if (recordingId) {
const { url, sourceMapURL } = script.source;
- Services.cpmm.sendAsyncMessage("RecordReplayGeneratedSourceWithSourceMap", {
- recordingId,
- url,
- sourceMapURL,
- });
+ Services.cpmm.sendAsyncMessage(
+ "RecordReplayGeneratedSourceWithSourceMap",
+ {
+ recordingId,
+ url,
+ sourceMapURL,
+ }
+ );
}
}
@@ -387,6 +390,7 @@ function eventListener(info) {
}
function SendRecordingFinished(recordingId) {
+ // here's the recording data...
const document = getWindow().document;
const data = {
recordingId,
@@ -1052,7 +1056,9 @@ function createProtocolObject(objectId, level) {
const obj = getObjectFromId(objectId);
const className = obj.class;
- RecordReplayControl.annotate(`CreateProtocolObject ${objectId} ${className} ${level}`);
+ RecordReplayControl.annotate(
+ `CreateProtocolObject ${objectId} ${className} ${level}`
+ );
let preview;
if (level != "none") {
preview = new ProtocolObjectPreview(obj, level).fill();
@@ -1139,7 +1145,11 @@ ProtocolObjectPreview.prototype = {
this.overflow = true;
return false;
}
- if (!force && this.level == "canOverflow" && this.numItems >= NumItemsBeforeOverflow) {
+ if (
+ !force &&
+ this.level == "canOverflow" &&
+ this.numItems >= NumItemsBeforeOverflow
+ ) {
this.overflow = true;
return false;
}
@@ -1171,7 +1181,9 @@ ProtocolObjectPreview.prototype = {
return;
}
try {
- RecordReplayControl.annotate(`PreviewCallGetter ${name} ${this.numItems}`);
+ RecordReplayControl.annotate(
+ `PreviewCallGetter ${name} ${this.numItems}`
+ );
const value = createProtocolValueRaw(this.raw[name]);
this.getterValues.set(name, { name, ...value });
} catch (e) {
diff --git a/devtools/startup/DevToolsStartup.jsm b/devtools/startup/DevToolsStartup.jsm
index 2a241c5c67f0..774482b100b9 100644
--- a/devtools/startup/DevToolsStartup.jsm
+++ b/devtools/startup/DevToolsStartup.jsm
@@ -82,6 +82,8 @@ const {
ContentProcessListener,
} = require("devtools/server/actors/webconsole/listeners/content-process");
+const { sendCommand } = require("devtools/server/actors/replay/connection");
+
// We don't want to spend time initializing the full loader here so we create
// our own lazy require.
XPCOMUtils.defineLazyGetter(this, "Telemetry", function () {
@@ -1444,9 +1446,9 @@ function saveRecordingInDB(description) {
);
const body = {
+ // Here's the user data
user_id: user.id,
recording_id: description.recordingId,
- id: description.recordingId,
url: description.url,
title: description.title,
duration: description.duration,
@@ -1461,7 +1463,9 @@ function saveRecordingInDB(description) {
headers: { "Content-Type": "application/json" },
})
.then(async (r) =>
- console.log(`succeeded in creating recording`, await r.json())
+ console.log(
+ `succeeded in creating recording ${description.url} ${description.recordingId}`
+ )
)
.catch((err) => console.error(err));
}
@@ -1861,6 +1865,11 @@ async function reloadAndStopRecordingTab(gBrowser) {
recordReplayLog(`FinishedRecording ${recordingId}`);
saveRecordingInDB(data);
+ sendCommand("Internal.setRecordingMetadata", {
+ recordingId: data.recordingId,
+ userId: data.userId,
+ url: data.url,
+ });
let viewHost = "https://replay.io";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment