Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Update search.search() page #35858

wants to merge 4 commits into from

Conversation

def00111
Copy link
Contributor

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

Clarify that, browser.search.search can fail.
@def00111 def00111 requested a review from a team as a code owner September 12, 2024 17:07
@def00111 def00111 requested review from willdurand and removed request for a team September 12, 2024 17:07
@github-actions github-actions bot added Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed labels Sep 12, 2024
Copy link
Contributor

github-actions bot commented Sep 12, 2024

Preview URLs

(comment last updated: 2024-09-22 19:03:56)

Copy link
Contributor

@PassionPenguin PassionPenguin left a 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.

Comment on lines 64 to 65
// This will fail, if the user has removed the search engine
// or has other version of the search engine installed (e.g. Wikipedia (de)).
Copy link
Contributor

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.

Suggested change
// 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

Copy link
Contributor Author

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.

I mean, if the user only has Wikipedia (de) installed then it will fail!

Copy link
Contributor

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Initiate a search manually
// initiate a search manually for fallback

Comment on lines 62 to 75
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",
});
}
Copy link
Contributor

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:

Suggested change
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",
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants