Repository navigation
Expand file tree
/
Copy pathsmoke.js
More file actions
54 lines (49 loc) · 1.75 KB
/
Copy pathsmoke.js
File metadata and controls
54 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Does content.js actually start? test.js only reaches the pure functions — start_() never runs
// there, which is how a `const` used above its own declaration shipped twice. This stubs the bare
// minimum of the browser the load path touches and asserts the script got all the way through.
const assert = require("assert");
const node = () => ({
style: {},
dataset: {},
classList: { add() {}, toggle() {}, contains: () => false },
textContent: "",
className: "",
hidden: false,
appendChild: (c) => c,
append() {},
replaceChildren() {},
addEventListener() {},
closest: () => null,
querySelector: () => null,
querySelectorAll: () => [],
getBoundingClientRect: () => ({ left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 }),
});
global.window = global;
global.location = { search: "?v=smoke", origin: "https://www.youtube.com" };
global.innerWidth = 1280;
global.innerHeight = 720;
global.MutationObserver = class {
observe() {}
disconnect() {}
};
global.setInterval = () => 0; // the real one would hold the process open forever
global.document = {
...node(),
head: node(),
body: node(),
documentElement: node(),
createElement: node,
createTextNode: (t) => ({ text: t }),
getElementById: () => null,
title: "smoke - YouTube",
};
global.chrome = {
runtime: { id: "smoke", sendMessage: (_m, cb) => cb?.({ text: "" }) },
storage: { local: { get: async () => ({}), set: async () => {} } },
};
require("./content.js");
// Reaching this line at all means the whole module body executed: no missing global, no use
// before initialisation, no syntax that only bites at runtime.
assert.ok(global.window.__im, "content.js did not finish starting");
assert.ok(Array.isArray(global.window.__im.sentences));
console.log("smoke ok");