Pipulate Free & Open Source SEO with & for LLMs

From URL Opener to Google Search: Evolving Widgets with Querystrings

Discover how to transform a basic URL opener into a powerful Google Search widget while maintaining atomic design principles and leveraging browser capabilities for seamless integration.

In our journey of building Pipulate workflows, we’ve reached an exciting milestone: evolving our URL opener into a specialized Google Search widget. This transformation showcases how to handle querystrings while maintaining our commitment to atomic steps and leveraging browser capabilities.

The Power of Browser Integration

Our URL opener widget uses Python’s webbrowser standard library to open URLs in your default browser. What makes this particularly powerful is its ability to work seamlessly across platforms:

import webbrowser
webbrowser.open(url)  # Works on WSL, macOS, and Windows

This simple line of code does something remarkable: even when running from a Linux subsystem (WSL) on Windows or macOS, it knows how to open URLs in your native OS’s default browser. This means we get access to:

  • Your default browser configuration
  • Saved passwords and automatic logins
  • Browser extensions and settings

Important note: Pipulate never has direct access to this data. It simply requests the browser to open a URL, and your browser handles the rest.

Understanding Browser Profiles

A key consideration when using browser-integrated widgets is profile management. Modern browsers like Chrome support multiple user profiles, and the webbrowser module will use whichever profile was last active. This has important implications:

  • Saved logins are profile-specific
  • Automatic authentication depends on the active profile
  • Different profiles may have different extensions enabled

Pro Tip: When using URL-opening widgets, ensure you’re using the browser profile that has the necessary saved logins for your workflow.

From URL Opener to Search Widget

Let’s look at how we evolved our URL opener into a Google Search widget. The key insight was recognizing that many URLs follow a pattern:

  1. Base URL: https://www.google.com/search
  2. Parameter: ?q=
  3. Query: User’s search term

Instead of having users enter the full URL, we can:

  1. Fix the base URL and parameter
  2. Let users enter just the query
  3. Construct and open the full URL

Here’s how we implemented this in our widget:

# Step Definition
Step(
    id='step_02',
    done='query',
    show='Google Search',
    refill=True,  # Allow query reuse
)

# Query Input
Input(
    type="text",
    name="query",
    placeholder="Enter search query",
    required=True,
    value=display_value,
    cls="contrast"
)

# URL Construction and Opening
search_url = f"https://www.google.com/search?q={query}"
webbrowser.open(search_url)

Maintaining Atomic Steps

While evolving the widget, we maintained our commitment to atomic steps. The Google Search widget:

  1. Has a single, clear purpose
  2. Combines related actions (query input + search)
  3. Provides immediate feedback
  4. Maintains its own state

This approach gives us several benefits:

  • Clear user mental model
  • Easy state management
  • Simple error handling
  • Reusable components

The Widget in Action

The completed Google Search widget provides:

  1. A clean input field for search queries
  2. Immediate execution of searches
  3. A “Search Again” button for convenience
  4. State preservation for query reuse

Here’s how it looks in the finalized state:

Card(
    H3(f"🔒 Google Search"),
    P(f"Search query: ", B(query_value)),
    Button(
        "Search Again ▸",
        type="button",
        _onclick=f"window.open('{search_url}', '_blank')",
        cls="secondary"
    )
)

Key Takeaways

  1. Browser Integration: Leverage existing browser capabilities without needing direct access
  2. Profile Awareness: Consider browser profiles in your workflow design
  3. Atomic Steps: Combine related actions while maintaining clear purpose
  4. State Management: Preserve user inputs for reuse and review
  5. Progressive Enhancement: Start simple and evolve widgets based on needs

What’s Next?

This pattern of evolving widgets from general to specific use cases opens up many possibilities:

  • Custom search engines
  • API endpoint testing
  • OAuth flow automation
  • Multi-step form submission

The key is to start with a solid foundation (like our URL opener) and evolve it thoughtfully, maintaining atomic steps and clear user interaction patterns along the way.

Remember: The power of these widgets comes from their ability to leverage your existing browser setup while maintaining a clear, focused purpose in your workflows.

Post #11 of 11 - April 16, 2025