Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 1afeca9

Browse files
committed
Revamp polydev around the devtools timeline APIs
Adds: * easy visualization of performance impact of custom elements inline with other performance information in browser timeline devtools * support for Custom Elements v0 Removes: * 'Polymer' panel in devtools. * The data model changed significantly so that code will need to be rewritten significantly. * ... and I kind don't believe in the feature that much. Being able to visualize the impact in the timeline seems superior to aggregate statistics. * Async tracking with zones. * I'd like to add this back. The zones API has changed completely, and it uses a decent amount of idiosyncratic terminology without defining any of it. Yay. Just needs some sweat, and this is useful as is.
1 parent a53ecdf commit 1afeca9

17 files changed

+706
-2145
lines changed

.clang-format

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BasedOnStyle: Google
2+
AllowShortBlocksOnASingleLine: false
3+
AllowShortCaseLabelsOnASingleLine: false
4+
AllowShortFunctionsOnASingleLine: None
5+
AllowShortIfStatementsOnASingleLine: false
6+
AllowShortLoopsOnASingleLine: false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/bower_components/
22
/node_modules/
33
/build/
4+
/src/document-context/*.js*

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"clang-format.style": "file",
4+
"clang-format.formatOnSave": true
5+
}

README.md

-9
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,3 @@ When changing files in src/ the dev workflow should work cover most use cases.
3939
Depending on the change you can either then close and reopen the devtools, or if
4040
you've made a change to the content-script or to element-zones, you must reload
4141
both the extension and any page you're testing it on.
42-
43-
### Working on element-zones
44-
45-
polydev uses the element-zones library to capture custom element stats. If you
46-
want to work on element-zones and see the results in polydev, then:
47-
48-
1. Run `bower link` in the element-zones directory
49-
2. Run `bower link element-zones` in the polydev directory
50-
3. Run `gulp` as normal

bower.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
"bower_components"
1212
],
1313
"dependencies": {
14-
"element-zones": "PolymerLabs/element-zones#^0.2.0",
15-
"imd": "PolymerLabs/imd#export",
1614
"iron-icon": "PolymerElements/iron-icon#~1.0.4",
1715
"iron-icons": "PolymerElements/iron-icons#~1.0.3",
1816
"paper-button": "PolymerElements/paper-button#~1.0.4",
1917
"paper-material": "PolymerElements/paper-material#~1.0.2"
2018
},
2119
"devDependencies": {
22-
"polymer": "Polymer/polymer#~1.1.1"
20+
"web-component-tester": "^4.3.5"
2321
}
2422
}

gulpfile.js

+28-35
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
'use strict';
22

3-
var crisper = require('gulp-crisper');
4-
var es = require('event-stream');
5-
var gulp = require('gulp');
6-
var eslint = require('gulp-eslint');
3+
const crisper = require('gulp-crisper');
4+
const es = require('event-stream');
5+
const gulp = require('gulp');
6+
const eslint = require('gulp-eslint');
7+
const child_process = require('child_process');
78

8-
gulp.task('default', ['manifest', 'lint', 'src', 'bower', 'element-zones', 'zone.js']);
9+
gulp.task('default', ['manifest', 'lint', 'src', 'bower']);
910

1011
gulp.task('lint', function() {
11-
return gulp.src('src/**/*.js')
12-
.pipe(eslint())
13-
.pipe(eslint.format());
12+
return gulp.src('src/*.js').pipe(eslint()).pipe(eslint.format());
1413
});
1514

1615
gulp.task('dev', function() {
17-
return gulp.watch(['src/**/*', 'bower_components/element-zones/**/*.js'], ['src']);
16+
return gulp.watch(['src/**/*'], ['src']);
1817
});
1918

20-
gulp.task('manifest', function () {
19+
gulp.task('manifest', function() {
2120
return gulp.src('manifest.json').pipe(gulp.dest('build/polydev/'));
2221
});
2322

24-
gulp.task('zone.js', function() {
25-
return gulp.src('node_modules/zone.js/dist/zone-microtask.js')
26-
.pipe(gulp.dest('build/polydev/vendor/'));
23+
gulp.task('compile', function(cb) {
24+
child_process.exec('tsc', function(err, stdout, stderr) {
25+
if (err) {
26+
console.log(stderr);
27+
}
28+
cb(err);
29+
});
2730
});
2831

29-
gulp.task('element-zones', function() {
30-
return gulp.src('bower_components/element-zones/lib/element-zones.js')
31-
.pipe(gulp.dest('build/polydev/vendor/'));
32+
gulp.task('src', ['compile'], function() {
33+
return es
34+
.merge(
35+
gulp.src('src/**/*.html').pipe(crisper()),
36+
gulp.src(['src/**/*', '!src/**/*.html']))
37+
.pipe(gulp.dest('build/polydev/src'));
3238
});
3339

34-
gulp.task('src', function() {
35-
return es.merge(
36-
gulp.src('src/**/*.html')
37-
.pipe(crisper()),
38-
gulp.src(['src/**/*', '!src/**/*.html']))
39-
.pipe(gulp.dest('build/polydev/src'));
40-
});
41-
42-
gulp.task('bower', function () {
43-
return es.merge(
44-
gulp.src([
45-
'!bower_components/{element-zones,element-zones/**}',
46-
'bower_components/**/*.html'])
47-
.pipe(crisper()),
48-
gulp.src([
49-
'!bower_components/{element-zones,element-zones/**}',
50-
'!bower_components/**/*.html',
51-
'bower_components/**/*']))
52-
.pipe(gulp.dest('build/polydev/bower_components'));
40+
gulp.task('bower', function() {
41+
return es
42+
.merge(
43+
gulp.src(['bower_components/**/*.html']).pipe(crisper()),
44+
gulp.src(['!bower_components/**/*.html', 'bower_components/**/*']))
45+
.pipe(gulp.dest('build/polydev/bower_components'));
5346
});

manifest.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Polymer DevTools Extension",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Shows information about Polymer elements",
55
"permissions": [
66
"tabs",
@@ -19,8 +19,9 @@
1919
],
2020
"devtools_page": "src/devtools.html",
2121
"web_accessible_resources": [
22-
"vendor/zone-microtask.js",
23-
"vendor/element-zones.js"
22+
"src/document-context/measure-custom-elements.js",
23+
"src/document-context/measure-custom-elements.js.map",
24+
"src/document-context/measure-custom-elements.ts"
2425
],
2526
"manifest_version": 2
2627
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"gulp": "^3.9.0",
1616
"gulp-babel": "^5.2.0",
1717
"gulp-crisper": "0.0.5",
18-
"gulp-eslint": "^1.0.0"
18+
"gulp-eslint": "^1.0.0",
19+
"typescript": "^2.0.0"
1920
}
2021
}

src/background.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
/**
22
* @license
33
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4-
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5-
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6-
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
4+
* This code may only be used under the BSD style license found at
5+
* http://polymer.github.io/LICENSE.txt
6+
* The complete set of authors may be found at
7+
* http://polymer.github.io/AUTHORS.txt
8+
* The complete set of contributors may be found at
9+
* http://polymer.github.io/CONTRIBUTORS.txt
710
* Code distributed by Google as part of the polymer project is also
8-
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11+
* subject to an additional IP rights grant found at
12+
* http://polymer.github.io/PATENTS.txt
913
*/
1014

11-
var pagePorts = new Map();
12-
var polymerPanelPorts = new Map();
15+
const pagePorts = new Map();
16+
const polymerPanelPorts = new Map();
1317

1418
// listen for polymer devtools panel, and element-zones content
1519
// script connections
16-
chrome.extension.onConnect.addListener(function(port) {
20+
chrome.extension.onConnect.addListener((port) => {
1721
if (port.name == 'polymer-panel') {
1822
console.log('polymer-panel connected', port);
1923

20-
port.onMessage.addListener(function(message, port) {
24+
port.onMessage.addListener((message, port) => {
2125
console.log('from polymer-panel', message, port);
22-
if (!message.messageType) return;
23-
var messageType = message.messageType;
26+
if (!message.messageType) {
27+
return;
28+
}
29+
const messageType = message.messageType;
2430
if (messageType === 'tab-id') {
2531
console.log('polymer-page tab-id', message.tabId);
2632
// save the port to the polymer devtools panel
@@ -30,28 +36,29 @@ chrome.extension.onConnect.addListener(function(port) {
3036
messageType: 'handshake',
3137
});
3238

33-
} else if (messageType === 'get-element-stats' ||
34-
messageType === 'clear-element-stats') {
39+
} else if (
40+
messageType === 'get-element-stats' ||
41+
messageType === 'clear-element-stats') {
3542
console.log('messageType', messageType);
3643
// relay to content script
37-
var tabId = message.tabId;
38-
var pagePort = pagePorts.get(tabId);
44+
const tabId = message.tabId;
45+
const pagePort = pagePorts.get(tabId);
3946
pagePort.postMessage({
4047
messageType: messageType,
4148
});
4249
}
4350
});
4451

45-
} else if (port.name =='element-zones') {
52+
} else if (port.name == 'element-zones') {
4653
console.log('element-zones.onConnect', port, port.sender.tab.id);
4754
// save the port to the element-zones content script
4855
pagePorts.set(port.sender.tab.id, port);
49-
port.onMessage.addListener(function(message, port) {
56+
port.onMessage.addListener((message, port) => {
5057
if (message.messageType == 'element-stats') {
5158
console.log('element-stats', message.data);
5259
// post to devtools panel
53-
var tabId = port.sender.tab.id;
54-
var polymerPanelPort = polymerPanelPorts.get(port.sender.tab.id);
60+
const tabId = port.sender.tab.id;
61+
const polymerPanelPort = polymerPanelPorts.get(port.sender.tab.id);
5562
console.log('polymer panel port', tabId, polymerPanelPort);
5663
console.assert(polymerPanelPort != null);
5764
polymerPanelPort.postMessage({
@@ -63,14 +70,14 @@ chrome.extension.onConnect.addListener(function(port) {
6370
}
6471
});
6572

66-
// chrome.extension.onDisconnect.addListener(function(port) {
73+
// chrome.extension.onDisconnect.addListener((port) => {
6774
// if (port.name == 'element-zones') {
6875
// console.log('element-zones.onDisconnect', port);
6976
// pagePorts.remove(port.sender.tab.id);
7077
// }
7178
// });
7279

73-
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
80+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
7481
console.log('background chrome.runtime.onMessage', request, sender);
7582
if (request.messageType == 'get_times') {
7683
console.log('background get_times');

src/content-script.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
/**
22
* @license
33
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4-
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5-
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6-
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
4+
* This code may only be used under the BSD style license found at
5+
* http://polymer.github.io/LICENSE.txt
6+
* The complete set of authors may be found at
7+
* http://polymer.github.io/AUTHORS.txt
8+
* The complete set of contributors may be found at
9+
* http://polymer.github.io/CONTRIBUTORS.txt
710
* Code distributed by Google as part of the polymer project is also
8-
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11+
* subject to an additional IP rights grant found at
12+
* http://polymer.github.io/PATENTS.txt
913
*/
1014

1115
(function() {
1216
'use strict';
1317

14-
let zoneJsScript = getFile('/vendor/zone-microtask.js');
15-
let elementZonesScript = getFile('/vendor/element-zones.js');
16-
let script = document.createElement('script');
17-
let root = document.body || document.head || document.documentElement;
18+
const measurementsScript =
19+
getFile('/src/document-context/measure-custom-elements.js');
1820

19-
script.appendChild(document.createTextNode(zoneJsScript));
20-
root.appendChild(script);
21+
const root = document.body || document.head || document.documentElement;
2122

22-
script = document.createElement('script');
23-
script.appendChild(document.createTextNode(elementZonesScript));
23+
const script = document.createElement('script');
24+
script.appendChild(document.createTextNode(measurementsScript));
2425
root.appendChild(script);
2526

26-
let backgroundPageConnection = chrome.runtime.connect({
27+
const backgroundPageConnection = chrome.runtime.connect({
2728
name: 'element-zones',
2829
});
2930

3031
// Forward requests for element stats to the target page.
31-
backgroundPageConnection.onMessage.addListener(function(request, sender, sendResponse) {
32-
window.postMessage({
33-
messageType: request.messageType,
34-
}, '*');
35-
});
32+
backgroundPageConnection.onMessage.addListener(
33+
(request, sender, sendResponse) => {
34+
window.postMessage({messageType: request.messageType}, '*');
35+
});
3636

3737
// Forward element-stats responses from the target page to the background page
3838
// to be further forwarded to the polymer-panel
@@ -50,7 +50,7 @@
5050
let response = null;
5151

5252
xhr.open('GET', extensionUrl, false);
53-
xhr.onload = function (e) {
53+
xhr.onload = function() {
5454
if (xhr.readyState === 4) {
5555
if (xhr.status === 200) {
5656
response = xhr.responseText;
@@ -59,11 +59,11 @@
5959
}
6060
}
6161
};
62-
xhr.onerror = function (e) {
62+
xhr.onerror = function() {
6363
console.error(xhr.statusText);
6464
};
6565
xhr.send(null);
6666
return response + '\n\n//# sourceURL=polydev' + localUrl;
6767
}
6868

69-
})();
69+
})();

src/devtools.html

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
</head>
1616
<body>
1717
<script>
18-
chrome.devtools.panels.create("Polymer",
19-
"icon.png",
20-
"src/polymer-panel.html",
21-
function(panel) {
22-
console.log("polymer-panel.html loaded");
23-
}
24-
);
18+
// Commented out temporarily.
19+
20+
// chrome.devtools.panels.create("Polymer",
21+
// "icon.png",
22+
// "src/polymer-panel.html",
23+
// function(panel) {
24+
// console.log("polymer-panel.html loaded");
25+
// }
26+
// );
2527
</script>
2628
</body>
2729
</html>

0 commit comments

Comments
 (0)