diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/ru/web/api/workerglobalscope | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/ru/web/api/workerglobalscope')
-rw-r--r-- | files/ru/web/api/workerglobalscope/importscripts/index.html | 73 | ||||
-rw-r--r-- | files/ru/web/api/workerglobalscope/index.html | 173 |
2 files changed, 246 insertions, 0 deletions
diff --git a/files/ru/web/api/workerglobalscope/importscripts/index.html b/files/ru/web/api/workerglobalscope/importscripts/index.html new file mode 100644 index 0000000000..75989503bd --- /dev/null +++ b/files/ru/web/api/workerglobalscope/importscripts/index.html @@ -0,0 +1,73 @@ +--- +title: WorkerGlobalScope.importScripts() +slug: Web/API/WorkerGlobalScope/importScripts +translation_of: Web/API/WorkerGlobalScope/importScripts +--- +<p>{{APIRef("Web Workers API")}}</p> + +<p>Метод <code><strong>importScripts()</strong></code> интерфейса {{domxref("WorkerGlobalScope")}} синхронно импортирует один или несколько скриптов, добавляя их в область видимости сервис-воркера.</p> + +<h2 id="Синтаксис">Синтаксис</h2> + +<pre class="brush: js notranslate">self.importScripts('foo.js'); +self.importScripts('foo.js', 'bar.js', ...);</pre> + +<h3 id="Параметры">Параметры</h3> + +<p><span class="tlid-translation translation" lang="ru"><span title="">Разделенный запятыми объект </span></span>{{domxref("DOMString")}} скриптов, которые должны быть импортированы. Пути к скриптам указываются относительно URL HTML документа.</p> + +<h3 id="Возвращаемое_значение">Возвращаемое значение</h3> + +<p><em>Нет.</em></p> + +<h3 id="Выбрасываемые_исключения">Выбрасываемые исключения</h3> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Исключение</th> + <th scope="col">Описание</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>NetworkError</code></td> + <td>Добавленные скрипты имеют неверные MIME тип (то есть не <code>text/javascript</code>).</td> + </tr> + </tbody> +</table> + +<h2 id="Пример">Пример</h2> + +<p>Если вы хотите использовать некоторую функциональность, опделённую файлом <code>foo.js</code>, необходимо сделать следующее:</p> + +<pre class="brush: js notranslate">importScripts('foo.js');</pre> + +<p><code>importScripts()</code> и <code>self.importScripts()</code> по сути эквивалентны — и то и другое вызывает функцию <code>importScripts()</code> в области видимости воркера.</p> + +<h2 id="Спецификации">Спецификации</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-workerglobalscope-importscripts', 'importScripts()')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Поддержка_браузерами">Поддержка браузерами</h2> + + + +<p>{{Compat("api.WorkerGlobalScope.importScripts")}}</p> + +<h2 id="Смотрите_Также">Смотрите Также</h2> + +<p>{{domxref("WorkerGlobalScope")}}</p> diff --git a/files/ru/web/api/workerglobalscope/index.html b/files/ru/web/api/workerglobalscope/index.html new file mode 100644 index 0000000000..8b0f33c7e3 --- /dev/null +++ b/files/ru/web/api/workerglobalscope/index.html @@ -0,0 +1,173 @@ +--- +title: WorkerGlobalScope +slug: Web/API/WorkerGlobalScope +tags: + - API + - Interface + - NeedsTranslation + - Reference + - TopicStub + - WorkerGlobalScope + - Workers +translation_of: Web/API/WorkerGlobalScope +--- +<p>{{APIRef("Web Workers API")}}</p> + +<p>The <code><strong>WorkerGlobalScope</strong></code> interface of the <a href="/en-US/docs/Web/API/Web_Workers_API">Web Workers API</a> is an interface representing the scope of any worker. Workers have no browsing context; this scope contains the information usually conveyed by {{domxref("Window")}} objects — in this case event handlers, the console or the associated {{domxref("WorkerNavigator")}} object. Each <code>WorkerGlobalScope</code> has its own event loop.</p> + +<p>This interface is usually specialized by each worker type: {{domxref("DedicatedWorkerGlobalScope")}} for dedicated workers, {{domxref("SharedWorkerGlobalScope")}} for shared workers, and {{domxref("ServiceWorkerGlobalScope")}} for <a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker</a>. The <code>self</code> property returns the specialized scope for each context.</p> + +<h2 id="Properties">Properties</h2> + +<p><em>This interface inherits properties from the {{domxref("EventTarget")}} interface and {{domxref("WindowOrWorkerGlobalScope")}} and {{domxref("WindowEventHandlers")}} mixins.</em></p> + +<h3 id="Standard_properties">Standard properties</h3> + +<p>{{domxref("WorkerGlobalScope.navigator")}} {{readOnlyinline}}</p> + +<dl> + <dd>Returns the {{domxref("WorkerNavigator")}} associated with the worker. It is a specific navigator object, mostly a subset of the {{domxref("Navigator")}} for browsing scopes, but adapted to workers.</dd> + <dt>{{domxref("WorkerGlobalScope.self")}} {{readOnlyinline}}</dt> + <dd>Returns a reference to the <code>WorkerGlobalScope</code> itself. Most of the time it is a specific scope like {{domxref("DedicatedWorkerGlobalScope")}}, {{domxref("SharedWorkerGlobalScope")}} or {{domxref("ServiceWorkerGlobalScope")}}.</dd> + <dt>{{domxref("WorkerGlobalScope.location")}} {{readOnlyinline}}</dt> + <dd>Returns the {{domxref("WorkerLocation")}} associated with the worker. It is a specific location object, mostly a subset of the {{domxref("Location")}} for browsing scopes, but adapted to workers.</dd> +</dl> + +<h3 id="Non-standard_properties">Non-standard properties</h3> + +<dl> + <dt>{{domxref("WorkerGlobalScope.performance")}} {{readOnlyinline}} {{Non-standard_inline}}</dt> + <dd>Returns the {{domxref("Performance")}} associated with the worker. It is a regular performance object, except that only a subset of its property and methods are available to workers.</dd> + <dt>{{domxref("WorkerGlobalScope.console")}} {{readOnlyinline}} {{Non-standard_inline}}</dt> + <dd>Returns the {{domxref("Console")}} associated with the worker.</dd> +</dl> + +<h3 id="Properties_implemented_from_elsewhere">Properties implemented from elsewhere</h3> + +<dl> + <dt>{{domxref("WindowOrWorkerGlobalScope.caches")}} {{readOnlyinline}}</dt> + <dd>Returns the {{domxref("CacheStorage")}} object associated with the current context. This object enables functionality such as storing assets for offline use, and generating custom responses to requests.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.indexedDB")}} {{readonlyInline}}</dt> + <dd>Provides a mechanism for applications to asynchronously access capabilities of indexed databases; returns an {{domxref("IDBFactory")}} object.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.isSecureContext")}} {{readOnlyinline}}</dt> + <dd>Returns a boolean indicating whether the current context is secure (<code>true</code>) or not (<code>false</code>).</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.origin")}} {{readOnlyinline}}</dt> + <dd>Returns the global object's origin, serialized as a string. (This does not yet appear to be implemented in any browser.)</dd> +</dl> + +<h2 id="Events">Events</h2> + +<dl> + <dt><code>error</code></dt> + <dd>Fired when an error occured.<br> + Also available via the {{domxref("WorkerGlobalScope.onerror")}} property.</dd> + <dt><code>offline</code></dt> + <dd>Fired when the browser has lost access to the network and the value of <code>navigator.onLine</code> switched to <code>false</code>.<br> + Also available via the {{domxref("WorkerGlobalScope.onoffline")}} property.</dd> + <dt><code>online</code></dt> + <dd>Fired when the browser has gained access to the network and the value of <code>navigator.onLine</code> switched to <code>true</code>.<br> + Also available via the {{domxref("WorkerGlobalScope.ononline")}} property.</dd> + <dt><code><a href="/en-US/docs/Web/API/WorkerGlobalScope/languagechange_event">languagechange</a></code></dt> + <dd>Fired at the global/worker scope object when the user's preferred languages change.<br> + Also available via the {{domxref("WorkerGlobalScope.onlanguagechange")}} property.</dd> +</dl> + +<dl> + <dt><code>close</code> {{non-standard_inline}} {{obsolete_inline}}</dt> + <dd>Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("close")}} event is raised.<br> + Also available via the {{domxref("WorkerGlobalScope.onclose")}} property.</dd> + <dt><code>rejectionhandled</code> {{non-standard_inline}}</dt> + <dd>An event handler for handled <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" title="The Promise object is used for deferred and asynchronous computations. A Promise represents an operation that hasn't completed yet, but is expected in the future."><code>Promise</code></a> rejection events.<br> + Also available via the {{domxref("WorkerGlobalScope.onrejectionhandled")}} property.</dd> + <dt><code>unhandledrejection</code> {{non-standard_inline}}</dt> + <dd>An event handler for unhandled <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" title="The Promise object is used for deferred and asynchronous computations. A Promise represents an operation that hasn't completed yet, but is expected in the future."><code>Promise</code></a> rejection events.<br> + Also available via the {{domxref("WorkerGlobalScope.onunhandledrejection")}} property.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<p><em>This interface inherits methods from the {{domxref("EventTarget")}} interface and {{domxref("WindowOrWorkerGlobalScope")}} and {{domxref("WindowEventHandlers")}} mixins.</em></p> + +<h3 id="Standard_methods">Standard methods</h3> + +<dl> + <dt>{{domxref("WorkerGlobalScope.importScripts()")}}</dt> + <dd>Imports one or more scripts into the worker's scope. You can specify as many as you'd like, separated by commas. For example:<code> importScripts('foo.js', 'bar.js');</code></dd> +</dl> + +<h3 id="Non-standard_methods">Non-standard methods</h3> + +<dl> + <dt>{{domxref("WorkerGlobalScope.dump()")}} {{non-standard_inline}}</dt> + <dd>Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's {{domxref("window.dump")}}, but for workers.</dd> +</dl> + +<h3 id="Methods_implemented_from_elsewhere">Methods implemented from elsewhere</h3> + +<dl> + <dt>{{domxref("WindowOrWorkerGlobalScope.atob()")}}</dt> + <dd>Decodes a string of data which has been encoded using base-64 encoding.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.btoa()")}}</dt> + <dd>Creates a base-64 encoded ASCII string from a string of binary data.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.clearInterval()")}}</dt> + <dd>Cancels the repeated execution set using {{domxref("WindowOrWorkerGlobalScope.setInterval()")}}.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.clearTimeout()")}}</dt> + <dd>Cancels the delayed execution set using {{domxref("WindowOrWorkerGlobalScope.setTimeout()")}}.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.createImageBitmap()")}}</dt> + <dd>Accepts a variety of different image sources, and returns a {{domxref("Promise")}} which resolves to an {{domxref("ImageBitmap")}}. Optionally the source is cropped to the rectangle of pixels originating at <em>(sx, sy)</em> with width sw, and height sh.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.fetch()")}}</dt> + <dd>Starts the process of fetching a resource from the network.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.setInterval()")}}</dt> + <dd>Schedules a function to execute every time a given number of milliseconds elapses.</dd> + <dt>{{domxref("WindowOrWorkerGlobalScope.setTimeout()")}}</dt> + <dd>Schedules a function to execute in a given amount of time.</dd> +</dl> + +<h3 id="Deprecated_methods">Deprecated methods</h3> + +<dl> + <dt>{{domxref("WorkerGlobalScope.close()")}}</dt> + <dd>Discards any tasks queued in the <code>WorkerGlobalScope</code>'s event loop, effectively closing this particular scope. In newer browser versions, <code>close()</code> is available on <code>DedicatedWorkerGlobalScope</code> and {{domxref("SharedWorkerGlobalScope.close", "SharedWorkerGlobalScope")}} instead. This change was made to stop <code>close()</code> being available on service workers, as it isn't supposed to be used there and always throws an exception when called (see {{bug(1336043)}}).</dd> +</dl> + +<h2 id="Example">Example</h2> + +<p>You won't access <code>WorkerGlobalScope</code> directly in your code; however, its properties and methods are inherited by more specific global scopes such as {{domxref("DedicatedWorkerGlobalScope")}} and {{domxref("SharedWorkerGlobalScope")}}. For example, you could import another script into the worker and print out the contents of the worker scope's <code>navigator</code> object using the following two lines:</p> + +<pre class="brush: js">importScripts('foo.js'); +console.log(navigator);</pre> + +<div class="note"> +<p>Since the global scope of the worker script is effectively the global scope of the worker you are running ({{domxref("DedicatedWorkerGlobalScope")}} or whatever) and all worker global scopes inherit methods, properties, etc. from <code>WorkerGlobalScope</code>, you can run lines such as those above without specifying a parent object.</p> +</div> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', '#workerglobalscope', 'WorkerGlobalScope')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.WorkerGlobalScope")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li>Other global object interface: {{domxref("Window")}}, {{domxref("DedicatedWorkerGlobalScope")}}, {{domxref("SharedWorkerGlobalScope")}}, , {{domxref("ServiceWorkerGlobalScope")}}</li> + <li>Other Worker-related interfaces: {{domxref("Worker")}}, {{domxref("WorkerLocation")}}, {{domxref("WorkerGlobalScope")}}, and {{domxref("ServiceWorkerGlobalScope")}}.</li> + <li><a href="/en-US/docs/Web/Guide/Performance/Using_web_workers">Using web workers.</a></li> +</ul> |