Giter VIP home page Giter VIP logo

Comments (8)

gonzarascon avatar gonzarascon commented on July 2, 2024

I have a similar issue here, have you found a solution?

from console-feed.

samdenty avatar samdenty commented on July 2, 2024

You should use the Hook function on iframe.contentWindow.console

from console-feed.

gonzarascon avatar gonzarascon commented on July 2, 2024

Yes, that works if you have an iframe.html separately and give that file as a src attribute to the <iframe /> element on js. But it still doesn't work with the srcDoc attribute.

from console-feed.

agneym avatar agneym commented on July 2, 2024

@gonzarascon I ended up ditching console-feed and settled on a custom solution. You can find that here

from console-feed.

samdenty avatar samdenty commented on July 2, 2024

@gonzarascon @boywithsilverwings Ah I see. I've debugged it, and it seems that the iframe with a srcdoc is loaded two-times. In the componentDidMount after you've called the Hook function, the iframe is reloaded meaning the console isn't hooked anymore.

You can prevent this by using setTimeout.

Ideally, the Hook function should be in a separate JS bundle loaded only inside the iframe and you should use postMessage to send logs to the parent window.

https://codesandbox.io/s/625r54ql8n

from console-feed.

gonzarascon avatar gonzarascon commented on July 2, 2024

You have an example of Hook inside an iframe? (For using vanilla js, for example). If the srcDoc of the iframe is updated, the console un-hooks again.

from console-feed.

samdenty avatar samdenty commented on July 2, 2024

It requires setting up a bundler, haven't published umd builds. You can see an example of it in use here Example:

Iframe:

import { Hook, Encode } from "console-feed";

Hook(window.console, log => {
  window.postMessage(log, "*");
});

Parent:

import { Decode } from "console-feed";

window.addEventListener("message", log => {
  Decode(log);
});

from console-feed.

akashdotsrivastava avatar akashdotsrivastava commented on July 2, 2024

@gonzarascon @boywithsilverwings Ah I see. I've debugged it, and it seems that the iframe with a srcdoc is loaded two-times. In the componentDidMount after you've called the Hook function, the iframe is reloaded meaning the console isn't hooked anymore.

You can prevent this by using setTimeout.

Ideally, the Hook function should be in a separate JS bundle loaded only inside the iframe and you should use postMessage to send logs to the parent window.

https://codesandbox.io/s/625r54ql8n

@samdenty The above sandbox example works nicely in Chrome/Firefox, but not on Safari. On Safari, the console component turns out to be blank. Any insights into why this would be happening or how we could get it working? Thanks.

from console-feed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.