-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99de40b
commit b70c027
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Do we really need it? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/); | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|