You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import 'package:web/web.dart' as web;
import 'dart:js_interop';
void test() {
web.WorkerGlobalScope.instance // not working.
// The only way I found is unsafe
// import 'dart:js_interop_unsafe'; is needed
globalContext.callMethod('importScripts'.toJS, "https://my/url.js".toJS);
}
I see WorkerGlobalScope is defined in package:web's lib/src/dom/html.dart file, suggesting Worker APIs are supported. But WorkerGlobalScope is an extension, not a class. How can I use it?
The text was updated successfully, but these errors were encountered:
The globalContext is the WorkerGlobalScope (which is an extension type) you want here (in dart:html, we just return self for instance), so just cast and use the result:
var globalScope = globalContext asWorkerGlobalScope;
globalScope.importScripts("https://my/url.js");
When writing a Web worker using Dart, using the now deprecated
dart:html
package, it is possible to access theWorkerGlobalScope
instance this way:Using
package:web
, how can I do the same?I see
WorkerGlobalScope
is defined in package:web'slib/src/dom/html.dart
file, suggesting Worker APIs are supported. But WorkerGlobalScope is an extension, not a class. How can I use it?The text was updated successfully, but these errors were encountered: