Bug 1563607 Part 2 - Attach to service workers in debugger when pref is enabled, r=jdescottes,jlast.

Depends on D47541

Differential Revision: https://phabricator.services.mozilla.com/D47542

--HG--
extra : source : 6d02ecfce856b46a71d1c0a2050f57c7736c81f8
This commit is contained in:
Brian Hackett 2019-11-06 20:20:36 +00:00
Родитель 3b48883f4b
Коммит 0af504981d
6 изменённых файлов: 38 добавлений и 2 удалений

Просмотреть файл

@ -16,6 +16,12 @@ import type {
import { createPause, prepareSourcePayload } from "./create";
import sourceQueue from "../../utils/source-queue";
import { recordEvent } from "../../utils/telemetry";
import { features } from "../../utils/prefs";
const {
WorkersListener,
// $FlowIgnore
} = require("devtools/client/shared/workers-listener.js");
const CALL_STACK_PAGE_SIZE = 1000;
@ -45,6 +51,13 @@ function setupEvents(dependencies: Dependencies) {
debuggerClient.mainRoot.on("processListChanged", () =>
threadListChanged("contentProcess")
);
// If we are attaching to service workers we need to listen to worker changes
// everywhere in the browser.
if (features.windowlessServiceWorkers) {
const workersListener = new WorkersListener(debuggerClient.mainRoot);
workersListener.addListener(() => threadListChanged("worker"));
}
}
async function paused(threadFront: ThreadFront, packet: PausedPacket) {

Просмотреть файл

@ -5,7 +5,8 @@
// @flow
import { addThreadEventListeners } from "./events";
import { prefs } from "../../utils/prefs";
import { prefs, features } from "../../utils/prefs";
import { sameOrigin } from "../../utils/url";
import type { DebuggerClient, Target } from "./types";
import type { ThreadType } from "../../types";
@ -64,12 +65,25 @@ async function attachTargets(type, targetLists, args) {
}
export async function updateWorkerTargets(type: ThreadType, args: Args) {
const { currentTarget } = args;
const { currentTarget, debuggerClient } = args;
if (!currentTarget.isBrowsingContext || currentTarget.isContentProcess) {
return;
}
const { workers } = await currentTarget.listWorkers();
if (features.windowlessServiceWorkers && currentTarget.url) {
const { service } = await debuggerClient.mainRoot.listAllWorkers();
for (const { active, id, url } of service) {
// Attach to any service workers that are same-origin with our target.
// For now, ignore service workers associated with cross-origin iframes.
if (active && sameOrigin(url, currentTarget.url)) {
const workerTarget = await debuggerClient.mainRoot.getWorker(id);
workers.push(workerTarget);
}
}
}
await attachTargets(type, workers, args);
}

Просмотреть файл

@ -186,6 +186,7 @@ export type Actions = {
newQueuedSources: (QueuedSourceData[]) => void,
fetchEventListeners: () => void,
updateThreads: typeof actions.updateThreads,
ensureHasThread: typeof actions.ensureHasThread,
setFramePositions: typeof actions.setFramePositions,
};
@ -256,6 +257,8 @@ export type DebuggerClient = {
traits: any,
getFront: string => Promise<*>,
listProcesses: () => Promise<{ processes: ProcessDescriptor }>,
listAllWorkers: () => Promise<*>,
getWorker: any => Promise<*>,
on: (string, Function) => void,
},
connect: () => Promise<*>,

Просмотреть файл

@ -143,6 +143,7 @@ export const features = new PrefsHelper("devtools.debugger.features", {
showOverlay: ["Bool", "overlay"],
inlinePreview: ["Bool", "inline-preview"],
watchpoints: ["Bool", "watchpoints"],
windowlessServiceWorkers: ["Bool", "windowless-service-workers"],
});
export const asyncStore = asyncStoreHelper("debugger", {

Просмотреть файл

@ -37,3 +37,7 @@ export const parse = memoize(function parse(url: string): any {
return defaultUrl;
}
});
export function sameOrigin(firstUrl: string, secondUrl: string) {
return parse(firstUrl).origin == parse(secondUrl).origin;
}

Просмотреть файл

@ -85,3 +85,4 @@ pref("devtools.debugger.features.dom-mutation-breakpoints", true);
pref("devtools.debugger.features.log-points", true);
pref("devtools.debugger.features.overlay", true);
pref("devtools.debugger.features.inline-preview", true);
pref("devtools.debugger.features.windowless-service-workers", false);