Web Intents 101: A Beginner's Guide

Author

Reads 8.2K

Web banner with online information on computer
Credit: pexels.com, Web banner with online information on computer

Web Intents are a way for websites to ask users for permission to access their device's features, such as location, camera, or contacts. This is done through an intent, which is a request sent from a website to the user's browser.

A user's browser, in turn, asks the user if they want to grant the requested permission. This is where the user's decision comes into play. If the user grants permission, the website can then access the requested feature.

Web Intents are not the same as pop-ups or alerts, which can be annoying and intrusive. Instead, they are a more user-friendly way for websites to request permission, allowing users to make informed decisions about what they share with websites.

Discover more: Nexus S

Web Intents Basics

Web Intents is an experimental framework for web-based inter-application communication and service discovery, modeled after the Intents system in Android. It allows two web applications to communicate with each other without either knowing the other's specifics.

Here's an interesting read: Google Sheet Highlight - and in Cells

Credit: youtube.com, Chrome Apps Office Hours: Building Apps with Web Intents

A Client page may invoke multiple Intents simultaneously, and specific Intent objects are immutable once created. This means that once an Intent is set, it can't be changed.

An Intent consists of an "action" string, a "type" string, and the data payload itself. The action string tells the service what kind of activity the user expects to be performed, such as "share" or "edit".

Here are the key components of an Intent:

  • Action: specifies the activity to be performed (e.g. "share" or "edit")
  • Type: specifies the data payload the service should expect
  • Data payload: the actual data being passed between services

The User Agent plays a crucial role in facilitating Intent delivery, verifying that the Service has a registration record supporting the action and type of the Intent being delivered.

Introduction to Web Intents

Web Intents is an experimental framework for web-based inter-application communication and service discovery. It's a way for web applications to talk to each other without needing to know the specifics of each other's code.

Web Intents consists of a discovery mechanism and a lightweight RPC system between web applications, modeled after the Intents system in Android. This allows two web applications to communicate with each other without needing to know each other's details.

Take a look at this: Building a Web Application

Credit: youtube.com, Introduction to Web Intents - Paul Kinlan

Here are some key features of Web Intents:

  • Supported by Google Chrome versions 18 to 23
  • Supported by a JavaScript shim in IE 8, IE 9, Opera, Safari, Firefox 3+, and Chrome 3+

Web Intents enable rich integration between web applications by facilitating the exchange of rich data. This is done while maintaining loose coupling and an open architecture, which has proven beneficial for the web.

An Intent is a user-initiated action delegated to a service, consisting of an "action" string, a "type" string, and the data payload. The service then performs the action specified in the Intent.

Intriguing read: Google Fi Pause Service

Terminology

An Intent is an action with accompanying data, which is to be performed by a Service of the user's choosing. This is the core of what makes Web Intents so powerful.

Registration is how a web page informs the User Agent that it (or another same-origin Service page) is capable of handling Intents. This is a crucial step in making Web Intents work.

Invocation refers to the API by which a Client page dispatches an Intent for handling. It's the way a web page requests a Service to perform an action.

A web page which creates an Intent and invokes the User Agent with it is a Client. This is the page that initiates the action.

A web page which can handle an Intent is a Service, possibly returning a piece of data to the calling Client page.

On a similar theme: Web Service Provider

Intent Object

Credit: youtube.com, Android Tutorial #9: Implicit intents, share activities via intent resolution & matching

The Intent Object is a crucial part of Web Intents, and it's what allows web applications to communicate with each other in a standardized way.

An Intent Object models a particular task that can be requested to be handled by Services. This means it's a way to describe what needs to be done, without specifying how it's done.

The Intent Object is immutable once created, which means its properties can't be changed after it's been created.

To create an Intent Object, you can use the object-literal constructor, which requires the action and type fields to be specified. All other fields are optional.

Here's a breakdown of the required fields:

Note that the Intent Object is used in the context of the Web Intents framework, and is not a standalone object that can be used on its own.

Invocation and Dispatch

The client invokes an intent by constructing an Intent object and calling the navigator.startActivity function on it. This function call is what sets the entire process in motion, allowing the User Agent to mediate the Service selection.

For your interest: Google Sheet Custom Function

Credit: youtube.com, How to launch a custom Android application using Ionic Web Intents

The User Agent will enumerate the list of registered Services that match the requested Intent action and type, presenting the user with the option to select which Service should handle the Intent. This selection is a crucial part of the process, as it allows the user to choose which Service is best suited to handle the Intent.

The callbacks passed to startActivity MUST provide specific signatures, which the User Agent will use to communicate with the Service. These signatures are non-negotiable, and any attempt to modify them will result in a Javascript exception.

If the user has no persistent information about a qualifying service for a particular intent, the User Agent SHOULD present the user with the option to select from the default services proposed by the client. This is where the suggestions parameter comes into play, providing the User Agent with a list of default services to choose from.

The User Agent MUST follow the matching algorithm of the "Matching action and type for delivery" section before delivering the Intent to a suggested service. This ensures that the correct Service is chosen for the job, and that the Intent is delivered in a way that makes sense for the user.

The steps in a particular Intent invocation are asynchronous, meaning that the Service receives the Intent delivery and prepares its Response in a separate execution context. This allows the Service to handle the Intent without interrupting the user's workflow.

Service Registration and Management

Credit: youtube.com, Google I/O 2012 - How to Build Apps that Love Each Other with Web Intents

Service registration is a crucial part of the web intents ecosystem. A User Agent loads a page with registration markup, and it should allow the user to configure that page as a web intents service.

The User Agent may remember that the page can handle intents, but it must not deliver an intent to a Service discovered in this way before the user has made a specific action allowing it. This ensures the user has control over which services can handle their intents.

The User Agent must not allow web pages to discover passively which services the user has configured to handle particular intents, or any intents, whether by enumeration or exact query.

Explore further: Free Website Rank Checker

Service Registration

Service Registration is a crucial part of the web intents system, and it's essential to understand how it works.

When the User Agent loads a page with registration markup, it SHOULD allow the user to configure that page as a web intents service. The details of this process are left up to the User Agent.

Consider reading: Html Web Page in a Web Page

Credit: youtube.com, Video 2: e-Services, Registration and Social Security ID Management

The User Agent MUST NOT deliver an intent to a Service discovered in this way before the user has made a specific action allowing it. This means the user must explicitly give permission for the service to handle intents.

The User Agent MUST NOT allow web pages the ability to discover passively which services the user has configured to handle particular intents, or any intents, whether by enumeration or exact query. This ensures the user's privacy and security.

Web pages can unregister themselves implicitly by removing all intent tags, or explicitly by keeping the tag present, but without action or type attributes.

Use Cases and Integration

Web Intents allow local web apps to invoke and handle intents, making it possible for users to interact with external helper applications. This integration enables users to access a wide range of services and tools, such as photo editing tools, social networking sites, and cloud storage lockers.

See what others are reading: Google Webmaster Tools Support

Credit: youtube.com, Ep 4 - Use Cases of CCIF | Understanding Router's Cross Chain Intent Framework (CCIF)

Local web apps can delegate tasks to third-party applications, just like the photo hosting application in Example 4 did by allowing users to edit images with a meme-maker or share them with friends on social networking sites. This loose coupling enables users to choose from a variety of tools and services to complete a task.

A user can select a service to share a link to their favorite social site, view a document in their preferred app, or edit an object in their favorite editor, as described in the use cases in Example 3. This user-centric approach allows users to take control of their interactions and choose the tools that best suit their needs.

Here are some examples of how Web Intents can be used:

  • Attaching a picture directly from Google Drive or Dropbox to a tweet.
  • Viewing a document in the user's preferred app.
  • Editing an object in the user's favorite editor.
  • Sharing a link to the user's favorite social site.

Use Cases and Needs

Web Intents aimed to solve a specific use case, but it ended up being too broad, making it difficult to iterate on the UX effectively. A more focused approach could have led to a different API design.

Engineer Developing App
Credit: pexels.com, Engineer Developing App

User X, who uses Twitter, wants to attach a picture from their Google Drive or Dropbox. User Y wants to view a document in their preferred app, while User B wants to edit an object in their favorite editor. User A wants to share a link on their favorite social site. These are just a few examples of common user problems that Web Intents could have solved.

By solving these common user problems, developers could have iterated on the UX more effectively. This might have even led to a different API design. The two main areas that Web Intents aimed to solve were User Agent Discovery of services and User invocation and selection of services.

Here are some specific use cases that Web Intents could have addressed:

  • User X wants to attach a picture from Google Drive or Dropbox to a tweet.
  • User Y wants to view a document in their preferred app.
  • User B wants to edit an object in their favorite editor.
  • User A wants to share a link on their favorite social site.

By solving these use cases, Web Intents could have provided a more seamless experience for users.

[Integration with External Apps]

Integration with External Apps is a key feature of Web Intents. It allows web apps to invoke and handle intents, which is particularly useful for tasks that require external assistance.

Credit: youtube.com, Use Cases Of Application Integration | OIC | K21Academy

According to example 1, "local web apps should be able to invoke and handle intents". This means that web apps can take advantage of external apps to perform tasks that they may not be capable of handling on their own.

Web Intents can be routed to external helper applications, as shown in example 2. For instance, a photo editing tool can be configured to interact with the browser to handle an image edit intent. This allows users to choose from a variety of external apps to perform a specific task.

One example of this is a photo hosting application that can delegate image editing to third-party applications, as described in example 3. This allows users to edit images using their preferred editor, and then share the result with friends.

Here are some examples of external apps that can be integrated with Web Intents:

  • Photo editing tools
  • Social media sharing apps
  • Cloud storage services
  • File sharing platforms

These external apps can be configured to handle specific intents, such as image editing or file sharing. This allows users to choose from a variety of options to perform a task, and enables web apps to take advantage of external expertise to provide a better user experience.

Platform and Security Considerations

Credit: youtube.com, Web Intents Wednesday

Web Intents are built on top of the Web Platform, which means they can be used in a variety of contexts, including web pages, mobile apps, and even desktop applications.

One of the key benefits of Web Intents is that they are secure, thanks to the use of HTTPS, which encrypts data in transit.

Web Intents also rely on the browser's permission system, which ensures that users have control over the data they share.

The Web Platform provides a robust security framework that includes features like same-origin policy and content security policy.

Web Intents can be used with any type of data, including files, images, and even text.

To ensure the security of Web Intents, developers can use features like CORS (Cross-Origin Resource Sharing) to restrict access to sensitive data.

Web Intents are designed to be extensible, allowing developers to add new features and functionality as needed.

The Web Platform's security features, such as the permission system and CORS, provide a solid foundation for secure Web Intents development.

Web Intents can be used to share data between different applications, including web pages and mobile apps.

Developers can use the Web Platform's APIs to create custom Web Intents that meet their specific needs.

Explore further: Dropbox Paper Tutorial

Implementation and Best Practices

Credit: youtube.com, Web Intents Wednesdays

To implement Web Intents, you can use the Web Intents API, which allows users to share data between web applications in a secure and private way. This API is supported by most modern browsers.

One of the best practices for implementing Web Intents is to handle errors and exceptions properly, as seen in the example of the Share Intent, which checks for the existence of the navigator.share method before attempting to share data.

Always specify the type of data you're sharing, such as text, image, or URL, to ensure the receiving application knows how to handle it. This is demonstrated in the example of the Share Intent, which specifies the type of data being shared as "text/plain".

When sharing data, make sure to include a title and description to provide context to the receiving application. The example of the Share Intent shows how to include a title and description when sharing data.

Credit: youtube.com, Web Intents.... again... maybe

The Web Intents API provides a way to handle the response from the receiving application, allowing you to react accordingly. This is shown in the example of the Share Intent, which handles the response from the navigator.share method.

Always test your Web Intents implementation thoroughly to ensure it works as expected in different scenarios. This includes testing with different browsers and devices to ensure compatibility.

Danny Orlandini

Writer

Danny Orlandini is a passionate writer, known for his engaging and thought-provoking blog posts. He has been writing for several years and has developed a unique voice that resonates with readers from all walks of life. Danny's love for words and storytelling is evident in every piece he creates.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.