How to use the @cliqz/adblocker.isUTF8 function in @cliqz/adblocker

To help you get started, we’ve selected a few @cliqz/adblocker 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 cliqz-oss / adblocker / packages / adblocker-webextension / adblocker.ts View on Github external
// because we do not support this encoding.
      filter.write(event.data);
      filter.disconnect();
      return;
    }

    // Try to guess encoding on first chunk received. The assumption is that
    // we will find either `charset` or `http-equiv` meta-tag in the header.
    // If none of this is found, then we fallback to using `isUTF8` which
    // will make sure `event.data` is valid utf-8 (this check is more
    // costly).
    if (utf8 === undefined) {
      utf8 =
        CHARSET_TAG_RE.test(decoded) ||
        CHARSET_HTTP_EQUIV_RE.test(decoded) ||
        isUTF8(new Uint8Array(event.data));
    }

    // We only proceed to filter this chunk if we could confirm that encoding
    // if utf-8. Otherwise we simply proxy the data as-is to not risk
    // breaking the page.
    if (utf8 === true) {
      filter.write(encoder.encode(htmlFilter.write(decoded)));
    } else {
      filter.write(event.data);
    }
  };