@@ -6,10 +6,6 @@ import {
66 setHostname ,
77} from '../storage'
88
9- interface HTMLElementEvent < T extends HTMLElement > extends Event {
10- target : T
11- }
12-
139async function reloadExtension ( ) : Promise < void > {
1410 browser . runtime . reload ( )
1511}
@@ -28,7 +24,9 @@ async function saveOptions(e: SubmitEvent): Promise<void> {
2824 }
2925
3026 const hostnameInput = document . querySelector < HTMLInputElement > ( '#hostname' )
31- let hostname = hostnameInput . value
27+ if ( ! hostnameInput ) return
28+
29+ const hostname = hostnameInput . value
3230
3331 const form = e . target as HTMLFormElement
3432 const button = form . querySelector < HTMLButtonElement > ( 'button' )
@@ -86,6 +84,8 @@ async function restoreOptions(): Promise<void> {
8684
8785 const hostname = await getHostname ( )
8886 const hostnameInput = document . querySelector < HTMLInputElement > ( '#hostname' )
87+ if ( ! hostnameInput ) return
88+
8989 if ( hostname !== undefined ) {
9090 hostnameInput . value = hostname
9191 }
@@ -104,5 +104,8 @@ document
104104 ?. addEventListener ( 'change' , toggleCustomBrowserInput )
105105const form = document . querySelector ( 'form' )
106106if ( form ) {
107- form . addEventListener ( 'submit' , saveOptions as EventListener )
107+ form . addEventListener ( 'submit' , ( e : Event ) => {
108+ e . preventDefault ( )
109+ saveOptions ( e as SubmitEvent )
110+ } )
108111}
0 commit comments