Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

navigator.share is not always a function

See original GitHub issue

Bug Report

navigator.share is undefined is many browsers, yet TypeScript reports it as “the function is always defined”

🔎 Search Terms

navigator.share share

🕗 Version & Regression Information

Version 4.1.5 & Nightly

⏯ Playground Link

💻 Code

if (navigator.share) {
    console.log('The native share feature is implemented');
} else {
    console.log('The native share feature is not implemented');

🙁 Actual behavior

TypeScript reports it as “the function is always defined”

🙂 Expected behavior

If should report navigator.share as maybe being present.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

rizadhcommented, Dec 16, 2021

Ran into the same issue. Discovered that using navigator['share'] instead also works around the Typescript error, at least with my installed version of TypeScript 4.5.3.

IllusionMHcommented, Feb 15, 2021

There is ton of definitions from Edge Web IDLs so I think this definition is one from Edge.

Read more comments on GitHub >

github_iconTop Results From Across the Web

navigator.share() is not a function - Stack Overflow
share() to experiment with websharing in a react app. When I call navigator.canShare() in react, I get the following run time error: TypeError: ......
Read more >
Navigator.share() - Web APIs - MDN Web Docs
An object containing data to share. Properties that are unknown to the user agent are ignored; share data is only assessed on properties...
Read more >
How to share anything from your website by Web Share API
You can use this in your function or anywhere you want. But before you do that you should remember one thing that it...
Read more >
"navigator.share" | Can I use... Support tables for HTML5 ...
5 Did not support share click that would trigger a fetch call ... Navigator API: share: data.text parameter. Usage % of. all users,...
Read more >
Allow your mobile visitors to easier share your articles ... - Phiilu
Browsers that support the Web Share API will expose the share method on the navigator object. There is also a canShare method, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found