-
Notifications
You must be signed in to change notification settings - Fork 1
/
devtools.js
89 lines (78 loc) · 8.41 KB
/
devtools.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"use strict";
(() => {
/**
* This script runs in the background as soon as Devtools is opened.
*
* We push actions temporarily to a queue, until the panel is opened, to avoid
* loading and processing of content that won't be visible to the user anyway.
*/
console.log("START: devtools.js");
let _panel;
let _queue = [];
function queue(action) {
_queue.push(action);
flush();
}
function clear() {
_queue = [];
}
function flush() {
if (_panel) {
for (let fn of _queue) {
fn(_panel);
}
_queue = [];
}
}
chrome.devtools.network.onNavigated.addListener(url => {
console.log("NAVIGATE: clear pending requests", url);
clear();
queue(panel => panel.onNavigation(url));
});
chrome.devtools.network.onRequestFinished.addListener(request => {
// console.log("REQUEST", request);
queue(panel => panel.onRequest(request));
});
chrome.devtools.panels.create("Server Log", "toolbar-icon.png", "panel.html", panel => {
console.log("CREATE PANEL", panel);
panel.onShown.addListener(function onShowPanel(window) {
console.log("SHOW PANEL");
panel.onShown.removeListener(onShowPanel); // run once only
_panel = window;
flush();
});
});
})();
/*
// this won't be necessary unless we need to connect to "background.js"
// at the moment it doesn't look like that will be necessary.
chrome.devtools.panels.create("Server Log", "toolbar-icon.png", "panel.html", panel => {
console.log("CREATE PANEL");
let panel_window: PanelWindow; // Going to hold the reference to panel.html's `window`
let data: string[] = [];
let port = chrome.runtime.connect({name: 'server-log'});
port.onMessage.addListener(function(msg) {
// Write information to the panel, if exists.
// If we don't have a panel reference (yet), queue the data.
if (panel_window) {
panel_window.do_something(msg);
} else {
data.push(msg);
}
});
panel.onShown.addListener(function tmp(window) {
panel.onShown.removeListener(tmp); // Run once only
panel_window = window as PanelWindow;
// Release queued data
let msg: string | undefined;
while (msg = data.shift()) {
panel_window.do_something(msg);
}
// Just to show that it's easy to talk to pass a message back:
panel_window.respond = function(msg: string) {
port.postMessage(msg);
};
});
});
*/
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGV2dG9vbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGV2dG9vbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLENBQUMsR0FBRyxFQUFFO0lBRUY7Ozs7O09BS0c7SUFFSCxPQUFPLENBQUMsR0FBRyxDQUFDLG9CQUFvQixDQUFDLENBQUM7SUFJbEMsSUFBSSxNQUErQixDQUFDO0lBRXBDLElBQUksTUFBTSxHQUFhLEVBQUUsQ0FBQztJQUUxQixTQUFTLEtBQUssQ0FBQyxNQUFjO1FBQ3pCLE1BQU0sQ0FBQyxJQUFJLENBQUMsTUFBTSxDQUFDLENBQUM7UUFFcEIsS0FBSyxFQUFFLENBQUM7SUFDWixDQUFDO0lBRUQsU0FBUyxLQUFLO1FBQ1YsTUFBTSxHQUFHLEVBQUUsQ0FBQztJQUNoQixDQUFDO0lBRUQsU0FBUyxLQUFLO1FBQ1YsSUFBSSxNQUFNLEVBQUU7WUFDUixLQUFLLElBQUksRUFBRSxJQUFJLE1BQU0sRUFBRTtnQkFDbkIsRUFBRSxDQUFDLE1BQU0sQ0FBQyxDQUFDO2FBQ2Q7WUFFRCxNQUFNLEdBQUcsRUFBRSxDQUFDO1NBQ2Y7SUFDTCxDQUFDO0lBRUQsTUFBTSxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsRUFBRTtRQUNsRCxPQUFPLENBQUMsR0FBRyxDQUFDLGtDQUFrQyxFQUFFLEdBQUcsQ0FBQyxDQUFDO1FBRXJELEtBQUssRUFBRSxDQUFDO1FBRVIsS0FBSyxDQUFDLEtB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