How to use the @hint/utils-dom.traverse function in @hint/utils-dom

To help you get started, we’ve selected a few @hint/utils-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webhintio / hint / packages / extension-browser / src / content-script / connector.ts View on Github external
setTimeout(async () => {
                try {
                    await this.evaluateInPage(`(${createHelpers})()`);

                    const snapshot: DocumentData = await this.evaluateInPage('__webhint.snapshotDocument(document)');

                    restoreReferences(snapshot);

                    this._document = new HTMLDocument(snapshot, location.href, this._originalDocument);

                    await this.sendFetchEndEvents();

                    await traverse(this._document, this._engine, resource);

                    /*
                     * Evaluate after the traversing, just in case something goes wrong
                     * in any of the evaluation and some scripts are left in the DOM.
                     */
                    const event = {
                        document: this._document,
                        resource
                    };

                    await this._engine.emitAsync('can-evaluate::script', event);

                    this._onComplete(null, resource);

                } catch (err) /* istanbul ignore next */ {
                    this._onComplete(err);
github webhintio / hint / packages / connector-puppeteer / src / connector.ts View on Github external
this._dom = createHTMLDocument(html, this._finalHref, this._originalDocument);

        // Process pending requests now that the dom is ready
        while (this._pendingRequests.length > 0) {
            const pendingRequest = this._pendingRequests.shift()!;

            await pendingRequest();
        }

        if (this._options.headless) {
            // TODO: Check if browser downloads favicon even if there's no content
            await getFavicon(this._dom, this.fetchContent.bind(this), this._engine);
        }

        if (this._targetBody) {
            await traverse(this._dom, this._engine, this._page.url());

            const event = {
                document: this._dom,
                resource: this._finalHref
            };

            await this._engine.emitAsync('can-evaluate::script', event);
        }
    }
github webhintio / hint / packages / connector-jsdom / src / connector.ts View on Github external
try {
                        // TODO: Use a DOM snapshot and copy node locations insead of serializing.
                        const html = this._window.document.documentElement.outerHTML;

                        const htmlDocument = createHTMLDocument(html, this.finalHref, this._originalDocument);

                        this._document = htmlDocument;

                        const evaluateEvent = {
                            document: htmlDocument,
                            resource: this.finalHref
                        };

                        await this.server.emitAsync('can-evaluate::script', evaluateEvent);

                        await traverse(htmlDocument, this.server, this.finalHref);

                        // We download only the first favicon found
                        await this.getFavicon(window.document.querySelector('link[rel~="icon"]'));

                        /*
                         * TODO: when we reach this moment we should wait for all pending request to be done and
                         * stop processing any more.
                         */
                        await this.server.emitAsync('scan::end', event);
                    } catch (e) /* istanbul ignore next */ {
                        reject(e);
                    }
                    resolve();

                }, this._options.waitFor);
            };
github webhintio / hint / packages / connector-local / src / connector.ts View on Github external
private async onParseHTML(event: HTMLParse) {
        this._document = event.document;
        this._evaluate = this.createJsdom(event.html).window.eval;

        await traverse(this._document, this.engine, event.resource);

        const canEvaluateEvent = {
            document: this._document,
            resource: this._href
        };

        await this.engine.emitAsync('can-evaluate::script', canEvaluateEvent);
    }