-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update search.search() page #35858
base: main
Are you sure you want to change the base?
Update search.search() page #35858
Conversation
Clarify that, browser.search.search can fail.
Preview URLs (comment last updated: 2024-09-22 19:03:56) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify that, browser.search.search() can fail.
browser.search.search() can easily fail, if the provided search engine could not be found!
It's alread said in parameter section that
engine
: The name of the search engine. If the search engine name doesn't exist, the function rejects the call with an error. If this property is omitted, the default search engine is used.
the current example indeed do not cover the common edge case where Wikipedia (en)
is not a search engine of the browser, and i do agree to have a catch clause and some notes on it?
though, i will still consider the change unnecessary to some extents. parameter section has made it very clear what will happened on search engine not found.
// This will fail, if the user has removed the search engine | ||
// or has other version of the search engine installed (e.g. Wikipedia (de)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having Wikipedia (de)
and Wikipedia (en)
will not fail the function. additionally, not all browser has Wikipedia (en)
bundled with them - removed
may not be accurate.
// This will fail, if the user has removed the search engine | |
// or has other version of the search engine installed (e.g. Wikipedia (de)). | |
// this will fail if `Wikipedia (en)` is not an engine of the browser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having
Wikipedia (de)
andWikipedia (en)
will not fail the function.
I mean, if the user only has Wikipedia (de)
installed then it will fail!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having
Wikipedia (de)
andWikipedia (en)
will not fail the function.I mean, if the user only has
Wikipedia (de)
installed then it will fail!
then what you actually wrote in your code controverts with what you means here. you just want to say Wikipedia (en)
is not a search engine of the browser.
disposition: "NEW_WINDOW", | ||
}); | ||
} catch (ex) { | ||
// Initiate a search manually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Initiate a search manually | |
// initiate a search manually for fallback |
async function search() { | ||
try { | ||
// this will fail if `Wikipedia (en)` is not an engine of the browser | ||
await browser.search.search({ | ||
query: "styracosaurus", | ||
engine: "Wikipedia (en)", | ||
disposition: "NEW_WINDOW", | ||
}); | ||
} catch (ex) { | ||
// initiate a search manually for fallback | ||
await browser.windows.create({ | ||
url: "https://en.wikipedia.org/w/index.php?title=Special:Search&search=styracosaurus", | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest updating the code comments:
async function search() { | |
try { | |
// this will fail if `Wikipedia (en)` is not an engine of the browser | |
await browser.search.search({ | |
query: "styracosaurus", | |
engine: "Wikipedia (en)", | |
disposition: "NEW_WINDOW", | |
}); | |
} catch (ex) { | |
// initiate a search manually for fallback | |
await browser.windows.create({ | |
url: "https://en.wikipedia.org/w/index.php?title=Special:Search&search=styracosaurus", | |
}); | |
} | |
async function search() { | |
try { | |
// try to search using the `Wikipedia (en)` search engine | |
await browser.search.search({ | |
query: "styracosaurus", | |
engine: "Wikipedia (en)", | |
disposition: "NEW_WINDOW", | |
}); | |
} catch (ex) { | |
// if the search fails, e.g., because the search engine isn't defined to the browser, initiate the search using a url | |
await browser.windows.create({ | |
url: "https://en.wikipedia.org/w/index.php?title=Special:Search&search=styracosaurus", | |
}); | |
} |
Clarify that, browser.search.search() can fail.
Description
Motivation
browser.search.search() can easily fail, if the provided search engine could not be found!
Additional details
Related issues and pull requests