{"id":22296429,"url":"https://github.com/knowledgecode/workerframe","last_synced_at":"2026-03-02T23:35:51.275Z","repository":{"id":30444023,"uuid":"33997441","full_name":"knowledgecode/workerframe","owner":"knowledgecode","description":"A tiny framework for Web Workers","archived":false,"fork":false,"pushed_at":"2015-09-23T13:35:05.000Z","size":200,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-16T11:52:36.349Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knowledgecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-15T14:05:43.000Z","updated_at":"2019-09-27T10:06:51.000Z","dependencies_parsed_at":"2022-07-31T10:18:28.942Z","dependency_job_id":null,"html_url":"https://github.com/knowledgecode/workerframe","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/knowledgecode/workerframe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fworkerframe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fworkerframe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fworkerframe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fworkerframe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knowledgecode","download_url":"https://codeload.github.com/knowledgecode/workerframe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fworkerframe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30025110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T23:31:36.176Z","status":"ssl_error","status_checked_at":"2026-03-02T23:31:20.819Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T17:45:34.150Z","updated_at":"2026-03-02T23:35:51.243Z","avatar_url":"https://github.com/knowledgecode.png","language":"JavaScript","readme":"# Worker Frame [![Circle CI](https://circleci.com/gh/knowledgecode/workerframe.svg?style=shield)](https://circleci.com/gh/knowledgecode/workerframe)\nThis is a tiny framework for Web Workers.  \n\n## Features\n- It is possible to write Worker's code in a same file.\n- Both Promise and Callback pattern support.\n- It is possible to use console.log in Workers (It will help with debugging).\n- Fast loading (1.2kb gz).\n\n## Install\n``` html\n\u003c!-- install a Promise polyfill for unsupported browser --\u003e\n\u003cscript src=\"es6-promise.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"workerframe.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\nCallback pattern:\n```javascript\nvar worker = new WorkerFrame(function () {\n    // it is executed this code in the worker context \u003e\u003e\u003e\n    self.on('add', function (data) {\n        self.message('answer', data[0] + data[1]);\n    });\n    // \u003c\u003c\u003c it is executed this code in the worker context\n});\n\nworker.on('answer', function (data) {\n    console.log(data);  // =\u003e 48\n});\nworker.message('add', [16, 32]);\n```\nIf transmit a message to worker via type \"foo\", the worker can receive it via type \"foo\". And vice versa.  \n\nPromise pattern:\n```javascript\nvar worker = new WorkerFrame(function () {\n    // it is executed this code in the worker context \u003e\u003e\u003e\n    self.on('add', function (data, success, failure) {\n        success(data[0] + data[1];\n    });\n    // \u003c\u003c\u003c it is executed this code in the worker context\n});\n\nworker.message('add', [16, 32])\n.then(function (data) {\n    console.log(data);  // =\u003e 48\n})\n.catch(function (err) {\n    // If the worker returns something error via failure(), this is called.\n});\n```\n\n## API\n### `new WorkerFrame(task)`\n```javascript\nvar foo = 'untouchable';\n\n// It is unable to access values and objects that are out of this function.\n// Note that it works in the worker thread.\nvar task = function () {\n    self.on('calc', function (data) {\n        self.message('complete', data.width * data.height);\n    });\n\n    // This will cause an error! (Because the `foo` is out of this function.)\n    console.log(foo);\n};\n\nvar worker = new WorkerFrame(task);\n```\n### `worker.message(type, data[, transferList])`\n```javascript\nworker.message('calc', { width: 640, height: 480 });\n```\n`transferList` is an optional array of Transferable objects (refer to [here](https://developer.mozilla.org/en-US/docs/Web/API/Transferable)).  \n### `worker.on(type, handler)`\n```javascript\nvar oncomplete = worker.on('complete', function (data) {\n    console.log('the task has been completed: ' + data);\n});\n```\nAlso it is able to catch errors that occur in a worker as below:  \n```javascript\nworker.on('error', function (err) {\n    console.log(err);\n});\n```\n### `worker.off(type, handler)`\n```javascript\nworker.off('complete', oncomplete);\n```\n### `worker.one(type, handler)`\nThe auto off version of `worker.on`.\n```javascript\nvar oncomplete = worker.one('complete', function (data) {\n    console.log('the task has been completed: ' + data);\n});\n```\n\n### `worker.close()`\nClose the worker cleanly (not \"abort\"). If it is also called this method, it is fired `close` event in the worker before actually closing. You may hook this event for performing finalization.\n```javascript\nvar worker = new WorkerFrame(function () {\n    self.on('close', function () {\n        console.log('I will be shut down soon!');\n    });\n});\n\nworker.close();\n```\n## Worker Context\nThe following functions are able to use only in worker context.\n### `self.message(type, data[, transferList])`\n```javascript\nvar worker = new WorkerFrame(function () {\n    self.message('say', 'hello');\n});\n```\n### `self.on(type, handler)`\n```javascript\nvar worker = new WorkerFrame(function () {\n    self.on('add', function (data) {\n        self.message('answer', data[0] + data[1]);\n    });\n});\n```\n```javascript\nvar worker = new WorkerFrame(function () {\n    self.on('add', function (data, success, failure) {\n        success(data[0] + data[1]);\n    });\n});\n```\n### `self.off(type, handler)`\n```javascript\nvar worker = new WorkerFrame(function () {\n    var add = self.on('add', function (data) {\n        self.message('answer', data[0] + data[1]);\n    });\n    self.off('add', add);\n});\n```\n### `self.one(type, handler)`\n```javascript\nvar worker = new WorkerFrame(function () {\n    self.one('add', function (data) {\n        self.message('answer', data[0] + data[1]);\n    });\n});\n```\n### `console.log(msg)`\n```javascript\nvar worker = new WorkerFrame(function () {\n    console.log('debuggable!!');\n});\n```\n## Caveats\n### `self.importScripts(path[, path, ...])`\nIf import some scripts via `self.importScripts` in this framework, they have to be given absolute path. As this framework has the `origin` property, make the absolute path with using it.\n```javascript\nvar worker = new WorkerFrame(function () {\n    // succeed\n    self.importScripts(self.origin + '/fetch.js');  // =\u003e http://example.com/fetch.js\n    // fail\n    self.importScripts('fetch.js');\n});\n```\n## `fetch / XMLHttpRequest`\n`fetch` and `XMLHttpRequest` apis also need absolute path.\n```javascript\nvar worker = new WorkerFrame(function () {\n    // succeed\n    fetch(self.origin + '/api/v1/foo');  // =\u003e http://example.com/api/v1/foo\n    // fail\n    self.importScripts('/api/v1/foo');\n});\n```\n\n## Browser Support\nChrome, Firefox, Safari, Opera, Android 4.4+, iOS 6+, and Internet Explorer 11.  \n\n## License\nMIT  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fworkerframe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknowledgecode%2Fworkerframe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fworkerframe/lists"}