firebase, google-cloud-workstations, web-share-api, permissions-policy, nextjs

navigator.share() “Permission Denied” in Firebase Studio / Google Cloud Workstations Preview Environment

Hi everyone,

I’m developing a Next.js application within Firebase Studio (which uses Google Cloud Workstations). My app uses the Web Share API (navigator.share()) to allow users to share content.

The API call is made from a secure (HTTPS) context and is triggered by a user click. When deployed to a standard hosting environment, navigator.share() works as expected.

However, when I run the app and preview it within Firebase Studio (or using the direct https://[PORT]-[WORKSTATION_NAME].[CLUSTER_ID].cloudworkstations.dev URL), navigator.share() fails with a “Permission denied” error in the browser console.

My understanding is that for navigator.share() to work within an <iframe>, the iframe needs the allow="web-share" attribute, or the hosting page/server needs to provide a Permissions-Policy: web-share=* HTTP header. I suspect the preview environment in Firebase Studio / Cloud Workstations might be rendering the app in an iframe without this permission enabled.

My Next.js application code already includes error handling for when navigator.share is not available or permission is denied:

// Simplified example from my component:
async function handleShare() {
  const shareData = { title: "My Lesson", text: "Check out this lesson plan!" };
  if (navigator.share) {
    try {
      await navigator.share(shareData);
      // Success toast
    } catch (err) {
      console.error("Share API Error:", err);
      // Error toast, e.g., "Share failed: Permission denied." or "Web Share not supported."
    }
  } else {
    // Fallback toast: "Web Share not supported."
  }
}

I’ve looked through the Google Cloud Workstations documentation for ways to configure application preview permissions, feature policies, or iframe attributes, but haven’t found anything specific to web-share.

Questions:

  1. Has anyone else encountered this “Permission denied” issue with navigator.share() in Firebase Studio or Google Cloud Workstations previews?
  2. Is there a known way to configure the Cloud Workstations preview environment (e.g., workstation configuration, custom Docker settings that affect the preview server, environment variables) to allow the web-share permission?
  3. Or is this a known limitation of the preview environment, meaning the Web Share API will only function correctly upon deployment to a different hosting platform?

Any insights, workarounds (if any exist at the platform level), or confirmations would be greatly appreciated!

Thanks!