Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit 831fd0a

Browse files
committed
Get each the style by actorID in client in order to begin to display as soon as possible
1 parent 121cb0e commit 831fd0a

5 files changed

Lines changed: 45 additions & 30 deletions

File tree

extension/experiments/inspectedNode/api-client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848
return this._invoke("getNodesInSubtree");
4949
},
5050

51-
async getStyle() {
52-
return this._invoke("getStyle");
51+
async getStyle(actoriID, skipPseudo) {
52+
return this._invoke("getStyle", [actoriID, skipPseudo]);
5353
},
5454

5555
async getStylesInSubtree() {
5656
return this._invoke("getStylesInSubtree");
5757
},
5858

59-
async _invoke(method) {
59+
async _invoke(method, parameters) {
6060
return new Promise(resolve => {
6161
const timestamp = Date.now();
6262

@@ -71,6 +71,7 @@
7171
port.postMessage({
7272
namespace: "browser.experiments.inspectedNode",
7373
method,
74+
parameters,
7475
timestamp,
7576
});
7677
});

extension/experiments/inspectedNode/api-server.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ browser.runtime.onConnect.addListener(port => {
1414
port.postMessage({ method: "onChange" });
1515
}
1616

17-
const onMessage = async ({ namespace, method, timestamp }) => {
17+
const onMessage = async ({ namespace, method, parameters = [], timestamp }) => {
1818
if (namespace !== "browser.experiments.inspectedNode") {
1919
return;
2020
}
@@ -25,7 +25,8 @@ browser.runtime.onConnect.addListener(port => {
2525
break;
2626
}
2727
default: {
28-
const result = await browser.experiments.inspectedNode[method](clientId);
28+
const result =
29+
await browser.experiments.inspectedNode[method](clientId, ...parameters);
2930
port.postMessage({ method, timestamp, result });
3031
break;
3132
}

extension/experiments/inspectedNode/api.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,22 @@ this.inspectedNode = class extends ExtensionAPI {
6060
await inspector.pageStyle.getApplied(node, option);
6161

6262
return styles.map(({ rule }) => {
63-
const { actorID: ruleId } = rule;
6463
let { declarations } = rule;
6564
declarations = declarations.filter(d => !d.commentOffsets);
66-
return declarations.length
67-
? { ruleId, declarations, node: _getNodeInfo(node) }
68-
: null;
69-
}).filter(rule => !!rule);
65+
return declarations.length ? declarations : null;
66+
}).filter(declarations => !!declarations);
7067
};
7168

72-
const _getStyle = async (clientId) => {
69+
const _getStyle = async (clientId, actorID, skipPseudo) => {
7370
await _setupClientIfNeeded(clientId);
7471

7572
const { inspector } = _clients.get(clientId);
7673
if (!inspector.selection.isConnected()) {
7774
return [];
7875
}
7976

80-
const node = inspector.selection.nodeFront;
81-
return _getAppliedStyle(inspector, node, { skipPseudo: true });
77+
const node = await inspector.walker.conn.getFrontByID(actorID);
78+
return _getAppliedStyle(inspector, node, { skipPseudo });
8279
};
8380

8481
const _getStylesInSubtree = async (clientId) => {
@@ -98,6 +95,7 @@ this.inspectedNode = class extends ExtensionAPI {
9895

9996
const _getNodeInfo = node => {
10097
const {
98+
actorID,
10199
id,
102100
className,
103101
attributes,
@@ -107,6 +105,7 @@ this.inspectedNode = class extends ExtensionAPI {
107105
} = node;
108106

109107
return {
108+
actorID,
110109
id,
111110
className: className.trim(),
112111
attributes,
@@ -163,8 +162,8 @@ this.inspectedNode = class extends ExtensionAPI {
163162
return _getNodesInSubtree(clientId);
164163
},
165164

166-
async getStyle(clientId) {
167-
return _getStyle(clientId);
165+
async getStyle(clientId, actorID, skipPseudo) {
166+
return _getStyle(clientId, actorID, skipPseudo);
168167
},
169168

170169
async getStylesInSubtree(clientId) {

extension/experiments/inspectedNode/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
{
3232
"type": "string",
3333
"name": "clientId"
34+
},
35+
{
36+
"type": "string",
37+
"name": "actorID"
38+
},
39+
{
40+
"type": "boolean",
41+
"name": "skipPseudo"
3442
}
3543
],
3644
"async": true

extension/sidebar-pane.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ async function _updateSelectedNode(selectedNode) {
2424

2525
const issues = [];
2626

27-
const { attributes, nodeName } = selectedNode;
27+
const { actorID, attributes, nodeName } = selectedNode;
2828
issues.push(
2929
..._webcompat.getHTMLElementIssues(nodeName, attributes, _targetBrowsers));
3030

31-
const declarationBlocks = await browser.experiments.inspectedNode.getStyle();
32-
for (const { declarations } of declarationBlocks) {
31+
const declarationBlocks =
32+
await browser.experiments.inspectedNode.getStyle(actorID, true);
33+
for (const declarations of declarationBlocks) {
3334
issues.push(
3435
..._webcompat.getCSSDeclarationBlockIssues(declarations, _targetBrowsers));
3536
}
@@ -71,19 +72,24 @@ async function _updateSubtree(selectedNode) {
7172
)
7273
}
7374

74-
progressEl.textContent = "Getting all descendants of the selected node";
75-
const declarationBlocks = await browser.experiments.inspectedNode.getStylesInSubtree();
76-
7775
progressEl.textContent = "Getting web compatibility issues for CSS styles";
78-
for (const { node, declarations } of declarationBlocks) {
79-
issues.push(
80-
...
81-
_webcompat.getCSSDeclarationBlockIssues(declarations, _targetBrowsers)
82-
.map(issue => {
83-
issue.node = node;
84-
return issue;
85-
})
86-
)
76+
for (const node of nodesInSubtree) {
77+
if (!_isValidElement(node)) {
78+
continue
79+
}
80+
81+
const declarationBlocks =
82+
await browser.experiments.inspectedNode.getStyle(node.actorID, false);
83+
for (const declarations of declarationBlocks) {
84+
issues.push(
85+
...
86+
_webcompat.getCSSDeclarationBlockIssues(declarations, _targetBrowsers)
87+
.map(issue => {
88+
issue.node = node;
89+
return issue;
90+
})
91+
);
92+
}
8793
}
8894

8995
progressEl.textContent = "Grouping all issues";

0 commit comments

Comments
 (0)