How can I access product search input with Javascript across all themes?

Is there a way to get access to product search input with Javascript that works with all themes? Every theme seems to have different HTML for the search input so one selector doesn’t work.

Or do I just have to create functionality that tries all selectors that themes use?

There are 2 ways to solve it

  • Try to cover all themes and search apps (or start with the most common ones and expand gradually) : This is a never ending game
  • All themes that use native search with post to /search, so either use that in pre scenario or check for page and page parameters in the post scenario (note, this doesn’t cover search apps)

Both strategies have trade-offs, so it is up to your use case of what would work best

1 Like

Thanks a lot for help!

1 Like