Web Share API 在 Firefox 上不起作用 (React, NextJS)

huangapple go评论52阅读模式
英文:

Web Share API Doesn't Work on Firefox (React, NextJS)

问题

The typical code (see below) to get the Web Share API doesn't work on my Firefox browser, but it does on Safari. This applies to both desktop and mobile.

// NextJS/React
if (navigator.share) await navigator.share(data);

But a very similar code seems to work (for any browser) on Vanilla JS according to these users on Reddit (Does the Web Share API work in Firefox on Android?) and this Codepen (Web Share API demo):

// VanillaJS
if (navigator.share) { 
   navigator.share({
      title: 'WebShare API Demo',
      url: 'https://codepen.io/ayoisaiah/pen/YbNazJ'
    }).then(() => {
      console.log('Thanks for sharing!');
    })
    .catch(console.error);
} else {
    shareDialog.classList.add('is-open');
}

My educated guess is that this must be a framework dependent issue. Has anyone had any trouble getting the Web Share API to work on NextJS, and Firefox specifically?

Alternatively, I wonder if the Codepen website has custom code to get the API working.

At any case, it can't be my browser configuration because I've tested both on mobile and desktop, and as I said, the Codepen linked works on my browser.

Therefore, this must be an issue with getting the API working on React/NextJS.

A satisfactory solution to this answer would be one that ideally manages to reproduce the situation and offers a clear explanation of the workaround or fix.

英文:

The typical code (see below) to get the Web Share API doesn't work on my Firefox browser, but it does on Safari. This applies to both desktop and mobile.

// NextJS/React
if (navigator.share) await navigator.share(data);

But a very similar code seems to work (for any browser) on Vanilla JS according to these users on Reddit (Does the Web Share API work in Firefox on Android?) and this Codepen (Web Share API demo):

//VanillaJS
if (navigator.share) { 
   navigator.share({
      title: 'WebShare API Demo',
      url: 'https://codepen.io/ayoisaiah/pen/YbNazJ'
    }).then(() => {
      console.log('Thanks for sharing!');
    })
    .catch(console.error);
    } else {
        shareDialog.classList.add('is-open');
    }

My educated guess is that this must be a framework dependent issue. Has anyone had any trouble getting the Web Share API to work on NextJS, and Firefox specifically?

Alternatively, I wonder if the Codepen website has custom code to get the API working.

At any case, it can't be my browser configuration because I've tested both on mobile and desktop, and as I said, the Codepen linked works on my browser.

Therefore, this must be an issue with getting the API working on React/NextJS.

A satisfactory solution to this answer would be one that ideally manages to reproduce the situation and offers a clear explanation of the workaround or fix.

答案1

得分: 1

https://caniuse.com/web-share
它说在Firefox上不受支持,您的子社区链接被锁定。

英文:

https://caniuse.com/web-share
It says it is not supported on Firefox and your link for the subreddit is locked.

huangapple
  • 本文由 发表于 2023年6月1日 00:30:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定