Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Oct 6, 2024
1 parent 961f20b commit 53a3ccd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 39 deletions.
32 changes: 32 additions & 0 deletions devtools/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://gist.github.com/enjalot/6472041
var indexedDB = window.indexedDB
var open = indexedDB.open('MyDatabase', 1)
open.onupgradeneeded = function () {
var db = open.result
var store = db.createObjectStore('MyObjectStore', { keyPath: 'id' })
var index = store.createIndex('NameIndex', ['name.last', 'name.first'])
}
open.onsuccess = function () {
var db = open.result
var tx = db.transaction('MyObjectStore', 'readwrite')
var store = tx.objectStore('MyObjectStore')
var index = store.index('NameIndex')

store.put({ id: 12345, name: { first: 'John', last: 'Doe' }, age: 42 })
store.put({ id: 67890, name: { first: 'Bob', last: 'Smith' }, age: 35 })

var getJohn = store.get(12345)
var getBob = index.get(['Smith', 'Bob'])

getJohn.onsuccess = function () {
console.log(getJohn.result.name.first) // => "John"
}

getBob.onsuccess = function () {
console.log(getBob.result.name.first) // => "Bob"
}

tx.oncomplete = function () {
db.close()
}
}
40 changes: 5 additions & 35 deletions devtools/target.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="modulepreload" href="/db.js" />
<title>Target</title>
<style>
.motto {
Expand Down Expand Up @@ -78,6 +79,9 @@
</div>
<div class="big"></div>
<div class="small"></div>
<div class="image">
<img src="https://chii.liriliri.io/logo.png" alt="placeholder" />
</div>
<script>
console.log('Page loaded!')
setTimeout(function () {
Expand All @@ -103,41 +107,7 @@
testFetch()
testWs()
</script>
<script>
// https://gist.github.com/enjalot/6472041
var indexedDB = window.indexedDB
var open = indexedDB.open('MyDatabase', 1)
open.onupgradeneeded = function () {
var db = open.result
var store = db.createObjectStore('MyObjectStore', { keyPath: 'id' })
var index = store.createIndex('NameIndex', ['name.last', 'name.first'])
}
open.onsuccess = function () {
var db = open.result
var tx = db.transaction('MyObjectStore', 'readwrite')
var store = tx.objectStore('MyObjectStore')
var index = store.index('NameIndex')

store.put({ id: 12345, name: { first: 'John', last: 'Doe' }, age: 42 })
store.put({ id: 67890, name: { first: 'Bob', last: 'Smith' }, age: 35 })

var getJohn = store.get(12345)
var getBob = index.get(['Smith', 'Bob'])

getJohn.onsuccess = function () {
console.log(getJohn.result.name.first) // => "John"
}

getBob.onsuccess = function () {
console.log(getBob.result.name.first) // => "Bob"
}

tx.oncomplete = function () {
db.close()
}
}
</script>
<script src="target.js"></script>
<script type="module" src="target.js"></script>
<script>
console.log('console right after target injected')
throw Error('exception right after target injected')
Expand Down
2 changes: 2 additions & 0 deletions devtools/target.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './db.js'

const targetOrigin = location.protocol + '//' + location.host
function sendToDevtools(message) {
devtoolsIframe.contentWindow.postMessage(
Expand Down
23 changes: 19 additions & 4 deletions src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import map from 'licia/map'
import filter from 'licia/filter'
import compact from 'licia/compact'
import contain from 'licia/contain'
import endWith from 'licia/endWith'

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

function getResources(type: string) {
return map(
filter(
performance.getEntries(),
(entry: any) => entry.initiatorType === type
),
filter(performance.getEntries(), (entry: any) => {
if (entry.entryType !== 'resource') {
return false
}

if (entry.initiatorType === type) {
return true
} else if (entry.initiatorType === 'other') {
// preload
if (type === 'script') {
if (endWith(entry.name, '.js')) {
return true
}
}
}

return false
}),
entry => entry.name
)
}

0 comments on commit 53a3ccd

Please sign in to comment.