Skip to content

Commit 42d19e4

Browse files
committed
fix: error catching
1 parent c7d7f35 commit 42d19e4

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

public/static/js/devtools.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function evalGetCssUsed(cancel = false) {
4040
},
4141
function (result, isException) {
4242
if (isException) {
43-
// showMessage("isException:",isException);
43+
console.log("evalGetCssUsed isException: ",isException);
4444
} else {
45-
// console.log(result);
45+
// console.log('evalGetCssUsed result: ',result);
4646
}
4747
}
4848
)

src/content.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const externalCssCache: { [index: string]: cssNodeObj } = {}
1111
//to store timers of testing if a html element matches a rule selector.
1212
const arrTimerOfTestingIfMatched: ReturnType<typeof setTimeout>[] = []
1313
let doc = document
14-
function getC($0: HTMLElement) {
14+
async function getC($0: HTMLElement) {
1515
arrTimerOfTestingIfMatched.forEach(function (ele) {
1616
clearTimeout(ele)
1717
})
@@ -24,28 +24,29 @@ function getC($0: HTMLElement) {
2424
typeof $0.nodeName === 'undefined'
2525
) {
2626
return
27-
} else {
28-
if ($0.nodeName.match(/^<pseudo:/)) {
29-
chrome.runtime.sendMessage({
30-
action: 'inform',
31-
info: "It's a pseudo element",
32-
})
33-
return
34-
} else if ($0.nodeName === 'html' || $0.nodeName.match(/^#/)) {
35-
chrome.runtime.sendMessage({
36-
action: 'inform',
37-
info: 'Not for this element',
38-
})
39-
return
40-
}
27+
}
28+
29+
if ($0.nodeName.match(/^<pseudo:/)) {
30+
chrome.runtime.sendMessage({
31+
action: 'inform',
32+
info: "It's a pseudo element",
33+
})
34+
return
35+
}
36+
37+
if ($0.nodeName === 'html' || $0.nodeName.match(/^#/)) {
38+
chrome.runtime.sendMessage({
39+
action: 'inform',
40+
info: 'Not for this element',
41+
})
42+
return
4143
}
4244

4345
let isInSameOrigin = true
4446
try {
4547
$0.ownerDocument.defaultView.parent.document
4648
} catch (e) {
4749
isInSameOrigin = false
48-
// console.log(e);
4950
}
5051

5152
if (isInSameOrigin) {
@@ -138,11 +139,13 @@ function getC($0: HTMLElement) {
138139
})
139140
}
140141

141-
chrome.runtime.sendMessage({
142-
action: 'evalGetCssUsed',
143-
info: 'page loaded',
144-
}).catch(()=>{
145-
// console.log('error',error);
146-
})
142+
chrome.runtime
143+
.sendMessage({
144+
action: 'evalGetCssUsed',
145+
info: 'page loaded',
146+
})
147+
.catch(() => {
148+
// console.log('error',error);
149+
})
147150

148151
export default getC

src/ui/Panel.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
/^(chrome|https:\/\/chrome\.google\.com\/webstore)/
3636
) !== null
3737
) {
38-
// showMessage('This page is protected by Chrome.<br>Try another page.')
3938
isGooglePreservedPages = true
4039
} else {
4140
isGooglePreservedPages = false

src/util/cssHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import convTextToRules from './convTextToRules'
88

99
const cssHelper = {
1010
mergeobjCss: function (a: cssObj, b: cssObj) {
11-
;['normRule', 'fontFace', 'keyFram'].forEach(function (ele) {
11+
['normRule', 'fontFace', 'keyFram'].forEach(function (ele) {
1212
if (!a[ele] || !b[ele]) {
1313
// console.log('NO '+ele);
1414
}
15-
a[ele] = a[ele].concat(b[ele])
15+
a[ele] = a[ele].concat(b[ele]).filter(e=>e)
1616
})
1717
},
1818
normRuleNodeToText: function (node) {

src/util/generateRulesAll.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ function generateRulesAll(
3030
// can be link tag
3131
cssNodeArr = externalCssCache[styleSheet.href];
3232
cssNodeArr.media = doc.styleSheets[x].media;
33-
traversalCSSRuleList(doc, externalCssCache, cssNodeArr).then(
34-
function (obj) {
35-
res(obj);
36-
}
37-
);
33+
traversalCSSRuleList(doc, externalCssCache, cssNodeArr).then(res);
3834
} else if(styleSheet.ownerNode instanceof Element) {
3935
// style tag
4036
let html: string = styleSheet.ownerNode.innerHTML;
@@ -59,16 +55,13 @@ function generateRulesAll(
5955
// the next operation is asynchronous
6056
// store the current x value
6157
let _x = x;
62-
convTextToRules(html, doc.location.href).then(function (
63-
cssNodeArr
64-
) {
65-
cssNodeArr.media = doc.styleSheets[_x].media;
66-
traversalCSSRuleList(doc, externalCssCache, cssNodeArr).then(
67-
function (obj) {
68-
res(obj);
69-
}
70-
);
58+
convTextToRules(html, doc.location.href).then(cssNodeObj=>{
59+
cssNodeObj.media = doc.styleSheets[_x].media;
60+
traversalCSSRuleList(doc, externalCssCache, cssNodeObj).then(res);
7161
});
62+
}else{
63+
// console.log('ProcessingInstruction', styleSheet.ownerNode);
64+
res({})
7265
}
7366
})
7467
);

0 commit comments

Comments
 (0)