How to use the @hint/utils-dom.getElementByUrl 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 / connector-puppeteer / src / lib / get-element-from-response.ts View on Github external
/**
     * We search the first URL because it will be the one
     * that was originally specified in the DOM.
     */
    const redirectChain = request.redirectChain();
    const requestUrl = redirectChain && redirectChain.length > 0 ?
        redirectChain[0].url() :
        source.url();

    /*
     * TODO: Check what happens with prefetch, etc.
     * `type` can be "parser", "script", "preload", and "other": https://chromedevtools.github.io/debugger-protocol-viewer/tot/Network/#type-Initiator
     */
    // The doesn't seem to be an initiator in puppeteer :/
    if (dom && requestUrl.startsWith('http')) {
        return getElementByUrl(dom, requestUrl);
    }

    return null;
};
github webhintio / hint / packages / connector-jsdom / src / resource-loader.ts View on Github external
public async fetch(url: string): Promise {
        /* istanbul ignore if */
        if (!url) {
            const promise = Promise.resolve(null);

            (promise as any).abort = () => { };

            return await promise;
        }

        /*
         * We need a `HTMLElement` instead of the element returned by jsdom.
         * To do so, we create a query from the element returned by jsdom and
         * look for it in our `HTMLDocument`.
         */
        const element = getElementByUrl(this._HTMLDocument, url);
        const urlAsUrl = new URL(url);
        let resourceUrl: string = urlAsUrl.href;

        /* istanbul ignore if */
        if (!urlAsUrl.protocol) {
            resourceUrl = new URL(resourceUrl, this._connector.finalHref).href;
        }

        // Ignore if the resource has already been fetched.
        if (this._connector.fetchedHrefs.has(resourceUrl)) {
            return null;
        }

        this._connector.fetchedHrefs.add(resourceUrl);

        debug(`resource ${resourceUrl} to be fetched`);
github webhintio / hint / packages / extension-browser / src / content-script / connector.ts View on Github external
private setFetchElement(event: FetchEnd) {
        const url = event.request.url;

        if (this._document) {
            event.element = getElementByUrl(this._document, url);
        }
    }