Skip to content

Commit 53a3ccd

Browse files
committed
chore: small changes
1 parent 961f20b commit 53a3ccd

File tree

4 files changed

+58
-39
lines changed

4 files changed

+58
-39
lines changed

devtools/db.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// https://gist.github.com/enjalot/6472041
2+
var indexedDB = window.indexedDB
3+
var open = indexedDB.open('MyDatabase', 1)
4+
open.onupgradeneeded = function () {
5+
var db = open.result
6+
var store = db.createObjectStore('MyObjectStore', { keyPath: 'id' })
7+
var index = store.createIndex('NameIndex', ['name.last', 'name.first'])
8+
}
9+
open.onsuccess = function () {
10+
var db = open.result
11+
var tx = db.transaction('MyObjectStore', 'readwrite')
12+
var store = tx.objectStore('MyObjectStore')
13+
var index = store.index('NameIndex')
14+
15+
store.put({ id: 12345, name: { first: 'John', last: 'Doe' }, age: 42 })
16+
store.put({ id: 67890, name: { first: 'Bob', last: 'Smith' }, age: 35 })
17+
18+
var getJohn = store.get(12345)
19+
var getBob = index.get(['Smith', 'Bob'])
20+
21+
getJohn.onsuccess = function () {
22+
console.log(getJohn.result.name.first) // => "John"
23+
}
24+
25+
getBob.onsuccess = function () {
26+
console.log(getBob.result.name.first) // => "Bob"
27+
}
28+
29+
tx.oncomplete = function () {
30+
db.close()
31+
}
32+
}

devtools/target.html

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<link rel="modulepreload" href="/db.js" />
78
<title>Target</title>
89
<style>
910
.motto {
@@ -78,6 +79,9 @@
7879
</div>
7980
<div class="big"></div>
8081
<div class="small"></div>
82+
<div class="image">
83+
<img src="https://chii.liriliri.io/logo.png" alt="placeholder" />
84+
</div>
8185
<script>
8286
console.log('Page loaded!')
8387
setTimeout(function () {
@@ -103,41 +107,7 @@
103107
testFetch()
104108
testWs()
105109
</script>
106-
<script>
107-
// https://gist.github.com/enjalot/6472041
108-
var indexedDB = window.indexedDB
109-
var open = indexedDB.open('MyDatabase', 1)
110-
open.onupgradeneeded = function () {
111-
var db = open.result
112-
var store = db.createObjectStore('MyObjectStore', { keyPath: 'id' })
113-
var index = store.createIndex('NameIndex', ['name.last', 'name.first'])
114-
}
115-
open.onsuccess = function () {
116-
var db = open.result
117-
var tx = db.transaction('MyObjectStore', 'readwrite')
118-
var store = tx.objectStore('MyObjectStore')
119-
var index = store.index('NameIndex')
120-
121-
store.put({ id: 12345, name: { first: 'John', last: 'Doe' }, age: 42 })
122-
store.put({ id: 67890, name: { first: 'Bob', last: 'Smith' }, age: 35 })
123-
124-
var getJohn = store.get(12345)
125-
var getBob = index.get(['Smith', 'Bob'])
126-
127-
getJohn.onsuccess = function () {
128-
console.log(getJohn.result.name.first) // => "John"
129-
}
130-
131-
getBob.onsuccess = function () {
132-
console.log(getBob.result.name.first) // => "Bob"
133-
}
134-
135-
tx.oncomplete = function () {
136-
db.close()
137-
}
138-
}
139-
</script>
140-
<script src="target.js"></script>
110+
<script type="module" src="target.js"></script>
141111
<script>
142112
console.log('console right after target injected')
143113
throw Error('exception right after target injected')

devtools/target.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './db.js'
2+
13
const targetOrigin = location.protocol + '//' + location.host
24
function sendToDevtools(message) {
35
devtoolsIframe.contentWindow.postMessage(

src/lib/resources.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import map from 'licia/map'
22
import filter from 'licia/filter'
33
import compact from 'licia/compact'
44
import contain from 'licia/contain'
5+
import endWith from 'licia/endWith'
56

67
let isPerformanceSupported = false
78
const performance = (window as any).webkitPerformance || window.performance
@@ -35,10 +36,24 @@ export function isImage(url: string) {
3536

3637
function getResources(type: string) {
3738
return map(
38-
filter(
39-
performance.getEntries(),
40-
(entry: any) => entry.initiatorType === type
41-
),
39+
filter(performance.getEntries(), (entry: any) => {
40+
if (entry.entryType !== 'resource') {
41+
return false
42+
}
43+
44+
if (entry.initiatorType === type) {
45+
return true
46+
} else if (entry.initiatorType === 'other') {
47+
// preload
48+
if (type === 'script') {
49+
if (endWith(entry.name, '.js')) {
50+
return true
51+
}
52+
}
53+
}
54+
55+
return false
56+
}),
4257
entry => entry.name
4358
)
4459
}

0 commit comments

Comments
 (0)