start method

Last updated: 2026-03-05T10:53:28.864Z

Metrics

LOC: 39 Complexity: 4 Params: 2

Signature

start(tabId, optionsOverride)

Source Code

    async start(tabId, optionsOverride) {
      if (state !== "inactive") {
        log.warn("Recording already active");
        return;
      }

      const opts: ScreenRecordOptions = {
        ...DEFAULT_SCREEN_RECORD_OPTIONS,
        ...optionsOverride,
      };

      try {
        stream = await acquireStream(tabId, opts);
        chunks = [];

        const mimeType = mimeForCodec(opts.codec);
        recorder = new MediaRecorder(stream, {
          mimeType,
          videoBitsPerSecond: opts.videoBitrate,
        });

        recorder.ondataavailable = (e: BlobEvent) => {
          if (e.data.size > 0) chunks.push(e.data);
        };

        recorder.onerror = (e) => {
          log.error("MediaRecorder error:", e);
          state = "inactive";
        };

        recorder.start(1000); // 1 s timeslice for progressive encoding
        state = "recording";
        log.info(`Recording started (tab ${tabId}, codec=${opts.codec})`);
      } catch (err) {
        log.error("Failed to start recording:", err);
        state = "inactive";
        throw err;
      }
    },

Dependencies (Outgoing)

graph LR start["start"] acquireStream["acquireStream"] mimeForCodec["mimeForCodec"] start -->|calls| acquireStream start -->|calls| mimeForCodec style start fill:#dbeafe,stroke:#2563eb,stroke-width:2px click start "f0ed2d1a28e21447.html" click acquireStream "1cf6715296051fa9.html" click mimeForCodec "3b29e1b45edc4afa.html"
TargetType
acquireStream calls
mimeForCodec calls

No incoming dependencies.