Coder Social home page Coder Social logo

Comments (5)

anilabhadatta avatar anilabhadatta commented on July 24, 2024 1

@gildas-lormeau #122 fixed it for seleniumbase as well, seleniumbase for some reason expects a new tab to disable to CORS issue(strange but hard to detect)
Will check the CDP implementation if that can be done to remove the existing approach
Thanks a lot for your support.

from educative.io_scraper.

anilabhadatta avatar anilabhadatta commented on July 24, 2024 1

CDP impl is done. closing this issue

from educative.io_scraper.

anilabhadatta avatar anilabhadatta commented on July 24, 2024

function injectScriptToHTML(scriptTag, location) {
if (location === "iframe") {
var frames = document.querySelectorAll('frame, iframe');
frames.forEach(frame => {
var frameDocument = frame.contentDocument || frame.contentWindow.document;
var targetElement = frameDocument.body || frameDocument.documentElement;
targetElement.appendChild(scriptTag.cloneNode(true));

                        subframe = targetElement.querySelector('frame, iframe');
                        var subframeDocument = subframe.contentDocument || subframe.contentWindow.document;
                        var subtargetElement = subframeDocument.body || subframeDocument.documentElement;
                        subtargetElement.appendChild(scriptTag.cloneNode(true));
                });
            }
            document.head.appendChild(scriptTag);
        }
                         
        function createScriptTagFromURL(url) {
            return fetch(url)
                .then(response => response.text())
                .then(data => {
                    var scriptElement = document.createElement('script');
                    scriptElement.type = 'text/javascript';
                    scriptElement.textContent = data;
                    return scriptElement;
                })
                .catch(error => {
                    console.error('Error loading script:', error);
                    return null;
                });
        }
        window.__define = window.define;
        window.__require = window.require;
        window.define = undefined;
        window.require = undefined;
        var baseurl = 'https://anilabhadatta.github.io/SingleFile/';
        var urls = [
        'lib/single-file-bootstrap.js',
        'lib/single-file-hooks-frames.js',
        'lib/single-file-frames.js',
        'lib/single-file.js'
        ];
        var fullUrls = urls.map(url => baseurl + url);
        
        for(let i=0; i< fullUrls.length; i++){
            createScriptTagFromURL(fullUrls[i])
                .then(scriptTag => {
                    if (scriptTag) {
                        if(i === 1 || i === 2){
                            injectScriptToHTML(scriptTag, "iframe") 
                        }
                        else {
                            injectScriptToHTML(scriptTag, "")
                        }
                    }
                });
        }

should fix

from educative.io_scraper.

gildas-lormeau avatar gildas-lormeau commented on July 24, 2024

Something similar to the code below (not tested) should work in a more generic way.

function injectScriptToHTML(scriptTag, doc = document) {
    var targetElement = doc.body || doc.documentElement;
    targetElement.appendChild(scriptTag.cloneNode(true));
    var frames = doc.querySelectorAll("frame, iframe");
    frames.forEach(frame => {
        if (frame.contentDocument) {
            injectScriptToHTML(scriptTag, frame.contentDocument);
        }
    });
}

/// ...
injectScriptToHTML(scriptTag);
/// ...

from educative.io_scraper.

anilabhadatta avatar anilabhadatta commented on July 24, 2024

@gildas-lormeau Thank you, the recursive solution fix it.
I will although try to impl the CDP solution

from educative.io_scraper.

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.