Skip to content
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

Printing failed because the contentWindow of the print iframe did not load #384

Open
rohit9430 opened this issue Jun 13, 2021 · 21 comments
Open

Comments

@rohit9430
Copy link

rohit9430 commented Jun 13, 2021

Printing failed because the contentWindow of the print iframe did not load

@MatthewHerbst
Copy link
Owner

Hello. Could you please give more details? What is the full error message? Also, what does your code look like? Thank you

@137942170
Copy link

react_devtools_backend.js:2560 Printing failed because the contentWindow of the print iframe did not load. This is possibly an error with react-to-print

@MatthewHerbst
Copy link
Owner

Could you please share the code you use to print? I've not seen this error reported before. Also, what version of React are you using?

@MatthewHerbst
Copy link
Owner

@rohit9430 @137942170 could you please provide a code sample and let me know what version of React you're using, and what browser/version?

@digio-shanefitzgerald
Copy link

digio-shanefitzgerald commented Oct 5, 2021

IOS version: 14.7.1
safari browser
Model: iphone 12
react: 16.13.1
react-to-print: 2.13.0,
Implementation:

import React, { useRef } from "react";
import { useReactToPrint } from "react-to-print";

const App = () => {
  const componentRef = useRef();
  const handlePrint = useReactToPrint({
    content: () => componentRef.current,
  });
  return (
    <div ref={componentRef}>
     // content to be printed
    </div>
    <Button onClick={handlePrint}>
      Print
    </Button>
  )
}

Screen Shot 2021-10-06 at 8 55 36 am

The weird part is it works in regular safari, but if the site is opened from an app in a webview, say like slack, that's when it errors.

@MatthewHerbst
Copy link
Owner

The weird part is it works in regular safari, but if the site is opened from an app in a webview, say like slack, that's when it errors.

Interesting. That's super helpful for helping me debug, thanks for the post. Not sure if it's something we can fix, but will try!

@swarad07
Copy link

swarad07 commented Oct 8, 2021

I can confirm this issue as well. Our logs are filled with users trying to launch the print window from web views inside apps like Facebook and Instagram. They receive this error, This happens in both Android (Chrome) and iOS (Safari).

console error: Printing failed because the `contentWindow` of the print iframe did not load. This is possibly an error with `react-to-print`. Please file an issue: https://github.com/gregnb/react-to-print/issues/

The print works fine if the website is opened normally in the browser.

@MatthewHerbst
Copy link
Owner

This is under active research, but at this time prospects are looking grim that we have any power here. I think this is completely in the hands of Google/Apple.

Resources I've found so far:

I've also found this hard to properly debug. The simplest way for me to debug this currently is with the "WebView Browser Tester" on the Android Studio emulator. However, running the library's example code there does not produce the error seen in this thread, and instead the print is a no-op, which seems to be the intended behavior by the Chromium team for printing iframes currently unfortunately.

Other resources I came across:

@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Oct 21, 2021

Further conversation with the Chromium team seems to confirm that WebView support for window.print isn't coming anytime soon 😢

https://bugs.chromium.org/p/chromium/issues/detail?id=322303#c34

There are a few options here:

  1. react-to-print can attempt to completely replace the content of the page with only the node to be printed, print it, and then restore the original value
    • Downsides: this may not be possible for all print environments, users would see potentially unexpected content, there are probably a lot of edge cases to consider that we don't even know about
  2. react-to-print can try to find a way to open the content in the user's actual web browser, not in the WebView
  3. Websites using react-to-print could tell users, or maybe even force users, to open the page in an actual web browser, not in the WebView

I think option 2 is the ideal, just need to figure out if it's possible, and if it is, how to do it

@HazimAlper
Copy link

Is there any update about the issue?

@MatthewHerbst
Copy link
Owner

Is there any update about the issue?

Unfortunately we're at the mercy of Android here 😢

@MatthewHerbst
Copy link
Owner

@tiffanytut0225 could you please make a working Codesandbox or similar replicating the problem ideally? It's hard to debug parts of your code

@tiffanytut0225
Copy link

@tiffanytut0225 could you please make a working Codesandbox or similar replicating the problem ideally? It's hard to debug parts of your code

The same code I provided works on Codesandbox. 😂
Maybe other things caused the error, I will try to find out.
Thank you for your reply.

@ricardo-fnd
Copy link

ricardo-fnd commented May 6, 2024

This error was just thrown in my application. The print works in:

  • safari 👍
  • firefox 👍
  • chrome 🚫

Its a web app, and in Chromes fails... But this code of mine is a released feature, and nothing changed (maybe chrome version)
When I click "print" nothing happens... But this one time, the error was logged to the console

@MatthewHerbst
Copy link
Owner

@ricardo-fnd can you be more specific please? Desktop Chrome or mobile Chrome? Assuming mobile Chrome, Android or iOS? Also, did you use a WebView or did you actually open in Chrome? WebView is not Chrome

@ricardo-fnd
Copy link

ricardo-fnd commented May 6, 2024

@MatthewHerbst Desktop chrome. nothing more. its an nextjs app... this was working before

@ricardo-fnd
Copy link

@MatthewHerbst I found the bug. removeAfterPrint was causing it. If I remove that prop, it works fine...

@ricardo-fnd
Copy link

@MatthewHerbst also documentTitle is not working 🤔

@ricardo-fnd
Copy link

@MatthewHerbst suddenly its working again, without any change... I dont know what to tell you lol. probably some version mismatch

@MatthewHerbst
Copy link
Owner

Strange, but glad it's working! If it occurs again please let me know

@JJozef
Copy link

JJozef commented Aug 4, 2024

I have these problems:

  1. In chrome mobile it does not work to print (IOS), basically it does not take correctly the content but it takes the whole page.
  2. In mobile the documentTitle, does not work, it takes the title of the site.
  3. On android it just doesn't work as it should, it takes another behaviour.
  4. On IOS, it only works on Safari, but the problem is that it takes more content than expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants