Skip to content

Commit

Permalink
startup
Browse files Browse the repository at this point in the history
  • Loading branch information
vdeturckheim committed Feb 5, 2019
1 parent 99de40b commit b70c027
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Do we really need it?
9 changes: 9 additions & 0 deletions devtools.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
<script src="lib/CDD.js"></script>
<script src="lib/InstructionEvent.js"></script>
<script src="devtools.js"></script>
</body>
</html>
23 changes: 23 additions & 0 deletions devtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
// Create a new panel


chrome.devtools.panels.create('SPAudit',
null,
'panel.html',
async function (panel) {

const cdt = new ChromeDebuggerDriver();
await cdt.start();

panel.onShown.addListener((panelWindow) => {

panelWindow.document.addEventListener(InstructionEvent.TYPE, (instruction) => {

const { data: { command, params } } = instruction;
console.log(command, params);
instruction.resolve('ok');
});
});
}
);
43 changes: 43 additions & 0 deletions lib/CDD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const ChromeDebuggerDriver = class {

constructor() {

this.target = null;
}

start() {

const self = this;
return new Promise((resolve) => {

chrome.debugger.getTargets((x) => {

self.target = x.find((p) => p.tabId === chrome.devtools.inspectedWindow.tabId);
if (self.target === null) {
return reject(new Error(`could not find target ${chrome.devtools.inspectedWindow.tabId}`));
}
return resolve();
});
});
}

sendCommand(command, params) {

const target = this.target;

if (target === null) {
return Promise.reject(new Error('call `start` on debugger to acquire target'))
}

return new Promise((resolve, reject) => {

chrome.debugger.sendCommand(target, command, params, (res) => {

if (res) {
return resolve(res);
}
return reject(/*TODO*/);
});
});
}
};
15 changes: 15 additions & 0 deletions lib/InstructionEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const TYPE = 'InstructionEvent';
const InstructionEvent = class extends Event {

constructor(command, params) {

super(TYPE);
this.data = { command, params };
this.promise = new Promise((resolve, reject) => {

this.resolve = resolve;
this.reject = reject;
});
}
};
InstructionEvent.TYPE = TYPE;
19 changes: 19 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name" : "SPAudit",
"version" : "0.1.0",
"description" : "SPAudit",
"background" : {
"scripts": [
"background.js"
]
},
"devtools_page": "devtools.html",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"permissions": [
"<all_urls>",
"webNavigation",
"debugger"
],
"manifest_version": 2,
"content_scripts": []
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "SPAudit",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sqreen/SPAudit.git"
},
"keywords": [],
"author": "",
"license": "TBD",
"bugs": {
"url": "https://github.com/sqreen/SPAudit/issues"
},
"homepage": "https://github.com/sqreen/SPAudit#readme"
}
13 changes: 13 additions & 0 deletions panel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html>
<head>

</head>
<body>
<script src="lib/InstructionEvent.js"></script>
<split-pane>
<div>JelloMdddasdfdsd</div>
</split-pane>
<button id="btn">CLICK</button>
<script src="panel.js"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function act() {

console.log('CLICK');
const evt = new InstructionEvent('msg', { ok: 1 });
evt.promise.then((x) => console.log('RESOLVE', x));

document.dispatchEvent(evt);
}

document.getElementById('btn')
.addEventListener('click', act);

0 comments on commit b70c027

Please sign in to comment.