123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import { DEBUG_BUILD } from './debug-build.js';
- import { logger } from './logger.js';
- import { getGlobalObject } from './worldwide.js';
- const WINDOW = getGlobalObject();
- function supportsErrorEvent() {
- try {
- new ErrorEvent('');
- return true;
- } catch (e) {
- return false;
- }
- }
- function supportsDOMError() {
- try {
-
-
-
- new DOMError('');
- return true;
- } catch (e) {
- return false;
- }
- }
- function supportsDOMException() {
- try {
- new DOMException('');
- return true;
- } catch (e) {
- return false;
- }
- }
- function supportsFetch() {
- if (!('fetch' in WINDOW)) {
- return false;
- }
- try {
- new Headers();
- new Request('http://www.example.com');
- new Response();
- return true;
- } catch (e) {
- return false;
- }
- }
- function isNativeFetch(func) {
- return func && /^function fetch\(\)\s+\{\s+\[native code\]\s+\}$/.test(func.toString());
- }
- function supportsNativeFetch() {
- if (typeof EdgeRuntime === 'string') {
- return true;
- }
- if (!supportsFetch()) {
- return false;
- }
-
-
- if (isNativeFetch(WINDOW.fetch)) {
- return true;
- }
-
-
- let result = false;
- const doc = WINDOW.document;
-
- if (doc && typeof (doc.createElement ) === 'function') {
- try {
- const sandbox = doc.createElement('iframe');
- sandbox.hidden = true;
- doc.head.appendChild(sandbox);
- if (sandbox.contentWindow && sandbox.contentWindow.fetch) {
-
- result = isNativeFetch(sandbox.contentWindow.fetch);
- }
- doc.head.removeChild(sandbox);
- } catch (err) {
- DEBUG_BUILD &&
- logger.warn('Could not create sandbox iframe for pure fetch check, bailing to window.fetch: ', err);
- }
- }
- return result;
- }
- function supportsReportingObserver() {
- return 'ReportingObserver' in WINDOW;
- }
- function supportsReferrerPolicy() {
-
-
-
-
- if (!supportsFetch()) {
- return false;
- }
- try {
- new Request('_', {
- referrerPolicy: 'origin' ,
- });
- return true;
- } catch (e) {
- return false;
- }
- }
- export { isNativeFetch, supportsDOMError, supportsDOMException, supportsErrorEvent, supportsFetch, supportsNativeFetch, supportsReferrerPolicy, supportsReportingObserver };
|