-
Notifications
You must be signed in to change notification settings - Fork 136
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
Generate PDF after "view-ready" event does not work #169
Comments
Can you include your code from your app where you emit the event? |
Thanks. Here is a basically what the code does: const element = <div>Test</div>;
const node = document.querySelector('.page');
ReactDOM.render(element, node, () => {
document.body.dispatchEvent(new Event('view-ready'));
}); even if I take it out of the callback the behavior is the same. It will always wait for 10 seconds or up to whatever |
Have you set the There is a test html page which you can also look at, run this command to try it out: |
But if you want to use |
thanks @codecounselor. I think I got it to work by wrapping the
Thanks again. |
Well I'm not a react expert but I know it uses a virtual dom so my guess is that when this runs in your render method perhaps document.body is not in the correct state? |
@codecounselor This still happens even if I totally remove React from the app. I wonder if it is some sort of race condition? maybe this |
That is a possibility, and might explain an issue I'm seeing as well. I will investigate this further and provide an update tomorrow. |
So as suspected, there is a race condition here where the main process does not send and execute the javascript in the renderer process (browser) before the page is loaded and emit's the ready event. I think what I'm going to do is add an acknowledgement event ( In the sample html page referenced above that would look like this: var eventEmitInterval = setInterval(function () {
document.body.dispatchEvent(new CustomEvent('view-ready', {}))
document.body.innerHTML += 'view-ready emitted...'
}, 10)
document.body.addEventListener('view-ready-ack', function(){
clearInterval(eventEmitInterval)
}) I'm not sure if there is another way to solve this, I will look a little bit deeper. But so far I have found nothing in the electron APIs that is of value. |
…rid of superfluous event listeners fraserxu#169
awesome. Thanks for the help. We are really excited about using this library and fixing this definitely helps. |
This has been released to npm as version 1.1.8 - note the change from |
I just can't seem to get this to work in any way. It will always wait the full 10 seconds.
Has anyone else been having problems with this feature?
The text was updated successfully, but these errors were encountered: