Open Bug 1745440 Opened 3 years ago Updated 2 years ago

Add async stacktrace support for log.entryAdded

Categories

(Remote Protocol :: WebDriver BiDi, task, P3)

task

Tracking

(Not tracked)

People

(Reporter: whimboo, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

(Whiteboard: [webdriver:backlog])

With bug 1731553 support for stackTrace has been landed that only covers synchronous call stacks. Running a browser chrome test as the one following which make use of asynchronous code currently do not report any stack by Gecko.

add_task(async function test_async_stack() {
  const script = `
    async function foo() { throw new Error("cheese"); }
    async function bar() { await foo(); }
    setTimeout(async function() { await bar(); }, 100);
  `;

  const listenerId = await listenToConsoleMessage("error");
  await createScriptNode(script);
  const { message, level, stack } = await getConsoleMessage(listenerId);
  is(level, "error", "Received expected log level");
  is(message, "Error: cheese", "Received expected log message");
  is(typeof stack, "object", "stack is of expected type Object");

  const frames = getFramesFromStack(stack);
  ok(Array.isArray(frames), "frames is of expected type Array");
  is(frames.length, 3, "Got expected number of stack frames");

  // First two stack frames are from our script
  checkStackFrame(frames[0], "about:blank", "foo", 2, 28);
  checkStackFrame(frames[1], "about:blank", "bar", 3, 22);
  checkStackFrame(frames[2], "about:blank", null, 4, 5);

  // Clear the console to avoid side effects with other tests in this file.
  await clearConsole();
});

We should investigate what's required to get async call stacks properly reported.

As discussed while investigating async error handling for script.evaluate async call stacks are only reported for Debuggees (ie globals on which addDebuggee was used).

We can lift this restriction by flipping the preference javascript.options.asyncstack_capture_debuggee_only to false, after what async stack traces will always be collected.

It's not clear yet what is the best approach here, between calling addDebuggee on all inspected globals, or flipping the preference. We probably want to pick the solution which has the least impact on the browser overall. Using addDebuggee would only impact the globals BiDi is currently interacting with. However it might have other consequences on the behavior/performance of that global. See usage of IsDebuggee at https://searchfox.org/mozilla-central/search?q=symbol:_ZNK2JS5Realm10isDebuggeeEv&redirect=false

Depends on: 1770477
Blocks: 1747061
No longer blocks: 1747061
Summary: Add stackTrace support for async call stacks → Add async stacktrace support for log.entryAdded
Whiteboard: [webdriver:backlog]
Blocks: 1747061

From Julian from bug 1747061:

We should reuse enableAsyncStack/disableAsyncStack as in Bug 1770477.
We can move this logic to the WindowGlobalMessageHandler who should be responsible to only enable/disable once depending on how many modules still require async stack traces (ie have some counter).

See Also: → 1828930
Depends on: 1830897
You need to log in before you can comment on or make changes to this bug.