Skip to content

File block: Use native feature detection for pdf support #63044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025

Conversation

asdofindia
Copy link
Contributor

Fixes #58891

Relies on https://developer.mozilla.org/en-US/docs/Web/API/Navigator/pdfViewerEnabled

What?

This PR adds a reliable way to detect pdf viewer support.

Why?

It fixes #58891 and deterministically looks for pdf viewer support.

How?

We check whether the browser signals that pdf viewer is available and if so, immediately assumes that the browser supports pdf viewing (without relying on user agent detection). It falls back to the old behavior if this pdfViewerEnabled property is not available in navigator.

Testing Instructions

  1. Open a post or page
  2. Insert a file block and choose a PDF
  3. Save the post.
  4. View from a mobile device

Testing Instructions for Keyboard

Same as above.

@asdofindia asdofindia requested a review from ajitbohra as a code owner July 2, 2024 10:02
Copy link

github-actions bot commented Jul 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: asdofindia <asdofindia@git.wordpress.org>
Co-authored-by: SirLouen <sirlouen@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: firestar300 <firestar300@git.wordpress.org>
Co-authored-by: khushdoms <khushdoms@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jul 2, 2024
Copy link

github-actions bot commented Jul 2, 2024

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @asdofindia! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@akasunil akasunil added the [Type] Bug An existing feature does not function as intended label Jul 2, 2024
@Mamaduka Mamaduka added the [Block] File Affects the File Block label Jul 3, 2024
@SirLouen SirLouen added [Type] Enhancement A suggestion for improvement. and removed [Type] Bug An existing feature does not function as intended labels Jul 31, 2025
@SirLouen
Copy link
Member

SirLouen commented Jul 31, 2025

Test Report

Description

✅ This report validates whether the indicated patch works as expected.

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/gutenberg/pull/63044.diff

Environment

  • WordPress: 6.9-alpha-60523
  • PHP: 8.2.29
  • Server: Apache/2.4.62 (Debian)
  • Database: mysqli (Server: 11.8.2-MariaDB-ubu2404 / Client: mysqlnd 8.2.29)
  • Browser: Firefox 141.0 (Mobile)
  • OS: Android
  • Theme: Twenty Seventeen 3.9
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 21.3.0
    • Test Reports 1.2.0

Actual Results

  1. ✅ Issue resolved with patch.

Additional Notes

  • I've reviewed it and this patch looks good to me. As I commented here, this is not a bug but an enhancement, because removing PDF support for mobiles was expected by default.

  • This support has been there in Firefox for a while, but it's been rolled now in Chrome Mobile browsers (my Chrome Mobile doesn't support this yet, but Firefox Mobiles does).

cc @Mamaduka

Supplemental Artifacts

Before the patch
image

After the patch:
image

@asdofindia
Copy link
Contributor Author

I've force pushed the whitespace change for fixing lint. The unit tests seem to fail for reasons outside this PR. Do let me know if anything else needs to be done.

@Mamaduka
Copy link
Member

Mamaduka commented Aug 1, 2025

Yes, it's an unrelated problem. This issue should be fixed once #71009 is merged, but will require another rebase.

Update: Merge the fix. Rebasing will resolve the problem now.

@Mamaduka Mamaduka changed the title Use native feature detection for pdf support File block: Use native feature detection for pdf support Aug 1, 2025
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @asdofindia!

@Mamaduka Mamaduka dismissed SirLouen’s stale review August 1, 2025 11:10

Feedback has been addressed.

@SirLouen SirLouen self-requested a review August 1, 2025 11:33
@Mamaduka Mamaduka merged commit f07ae42 into WordPress:trunk Aug 1, 2025
63 of 64 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Aug 1, 2025
@asdofindia asdofindia deleted the patch-1 branch August 1, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] File Affects the File Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDF embedding/preview is greedily blocked on Android Firefox/Chrome even though it should work
4 participants