File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ document.addEventListener("DOMContentLoaded", function (e) {
88 console . log ( "captured cleanly!" ) ;
99
1010 let form = { } ;
11- form . query = document . getElementById ( "query" ) . value ;
11+ form . query = document . getElementById ( "query" ) . value . trim ( ) ;
1212 form . commercial = document . getElementById ( "commercial" ) . checked ;
1313 form . modify = document . getElementById ( "modify" ) . checked ;
14- selectedEngine = document . querySelector (
14+ let selectedEngine = document . querySelector (
1515 'input[name="search-engine"]:checked' ,
1616 ) ;
1717 form . searchEngine = selectedEngine . value ;
@@ -24,8 +24,15 @@ document.addEventListener("DOMContentLoaded", function (e) {
2424
2525 // navigate behavior
2626 function navigateTo ( link ) {
27- if ( link ) {
28- window . open ( link , "_blank" ) ;
27+ try {
28+ // Validate the URL using the URL constructor
29+ new URL ( link ) ; // If the URL is invalid, it will throw an error
30+ if ( link ) {
31+ window . open ( link , "_blank" ) ; // If valid, open the link in a new tab
32+ }
33+
34+ } catch ( error ) {
35+ console . error ( "Error occurred: " , error ) ;
2936 }
3037 }
3138
You can’t perform that action at this time.
0 commit comments