项目 / jcputney/scorm-again
用于运行 SCORM 1.2 和 SCORM 2004 课件的 JavaScript 运行时库,不绑定特定学习管理系统;若未配置提交地址,会记录函数调用和数据而不向远端提交。它不是学习管理系统,也不负责上传或校验课件包。可用 `npm install scorm-again` 或 `yarn add scorm-again` 安装,再按说明创建 `Scorm12API` 或 `Scorm2004API` 并挂到 `window`,供课件发现。文档与示例见[项目站点](https://jcputney.github.io/scorm-again/),说明也写在[仓库 README](https://github.com/jcputney/scorm-again)。
本站整理,非 GitHub 官方 description。
官方快照(gh_history.db,2026-11-25):总榜 未进 Top50 · 日榜 未进 Top50 · 周榜未满 7 天基线(官方不生成) · 月榜暂无官方口径;下方四卡为站内趋势聚合(周卡按上榜次数,非官方 7 日增量窗)。
以下三段按该项目自己的 GitHub README 章节摘录(可合理截断并标明);README 没有对应章节的留空,不编造。
scorm-again 可通过 script 引入完整或单版本构建,也可 npm 安装后导入 Scorm12API/Scorm2004API,并支持跨 iframe 的 CrossFrameLMS/CrossFrameAPI 通信。
该项目实现符合 SCORM 规范的同步提交并可获知 LMS 成败,提供完整的 SCORM 2004 编排导航,支持沙盒 iframe 跨帧通信与离线存储并断网后在恢复联网时同步回 LMS。
来自 GitHub 仓库 README / 主页介绍正文,正文较长,已截断:保留前 20000 字符(原始 58,894 字节),完整内容见 GitHub 仓库。
# scorm-again
A modern, fully-tested JavaScript runtime for SCORM 1.2 and SCORM 2004.
---
[](https://github.com/jcputney/scorm-again/actions)
[](https://codecov.io/gh/jcputney/scorm-again)



[](https://www.npmjs.com/package/scorm-again)

[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=NF5MPZJAV26LE)
> **Upgrading from v2.x?** See the [Migration Guide](MIGRATION.md) for breaking changes and migration steps.
## Overview
This project provides a stable, tested platform for running SCORM 1.2 and SCORM 2004 modules. It is designed to be LMS-agnostic and can run without a backing LMS, logging all function calls and data instead of committing if an LMS endpoint is not configured.
### Key Features in v3.0.0
- **SCORM-compliant synchronous commits** - Commits now block and return actual LMS success/failure
- **SCORM 2004 Sequencing** - Complete implementation of sequencing and navigation
- **Cross-Frame Communication** - Run SCORM content in sandboxed iframes
- **Offline Support** - Store and sync data when offline
- **Improved Validation** - Stricter spec compliance with better error messages
### Breaking Changes Summary
The most significant breaking changes in v3.0.0:
1. **AICC support removed** - AICC uses HACP, not a JavaScript API
2. **Commits are synchronous by default** - Better SCORM compliance
3. **`asyncCommit` renamed** - Now `useAsynchronousCommits` + `throttleCommits`
See [MIGRATION.md](MIGRATION.md) for the complete list and migration steps.
## What is this not and what doesn't it do?
1. This is not an LMS
1. This does not handle the uploading and verification of SCORM modules (if you need a way to
verify and parse modules, I have written a library in Java that can be used to
extract the manifest and other
metadata: [jcputney/elearning-module-parser](https://github.com/jcputney/elearning-module-parser))
## Cross-Frame Communication
> **Note:** The Cross-Frame Communication feature is available in scorm-again v3.0.0+
> It's implemented with a cache-first shim (no SharedArrayBuffer) and a Proxy-based façade.
### Purpose of CrossFrameLMS and CrossFrameAPI
The Cross-Frame Communication feature lets SCORM content run inside sandboxed or cross-origin
iframes while still talking to the real SCORM API in the parent frame. It's ideal when:
- Loading SCORM content in a sandboxed iframe for extra security
- Your app has a multi-frame architecture (e.g. host frame + content frame)
- You need to avoid cross-origin restrictions between content and the LMS
- You want to isolate SCORM runtime calls from your main application logic
There are two core pieces:
1. **CrossFrameLMS**
- Lives in the **parent** frame where the real SCORM API is initialized
- Listens for `postMessage` calls from child frames
- Invokes the actual SCORM methods (Initialize, GetValue, SetValue, Commit, Terminate, etc.)
- Posts back `{ messageId, result, error }`
2. **CrossFrameAPI**
- Lives in the **child** (content) frame and replaces the global `API` / `API_1484_11`
- Uses a JavaScript `Proxy` so you don't need to predefine every SCORM method
- **Synchronously** returns cached values or defaults for `GetValue`, `Initialize`, `Commit`,
`SetValue`, `Finish`, etc.
- **Asynchronously** sends a `postMessage` to refresh the cache and update `GetLastError` behind
the scenes
- Caches the current state of the CMI object in the child frame, so that most calls are
synchronous and accurate
- Handles the `LMSInitialize` and `LMSFinish` calls to the LMS in the parent frame
- Does not block the main thread. It needs `Proxy`, so it does not work in IE11
Both constructors accept an optional **origin** parameter.
`CrossFrameLMS(api, origin)` validates incoming messages against the child's
origin (default `"*"`), while `CrossFrameAPI(origin, targetWindow)` uses the
origin when posting messages to the parent (also default `"*"`).
### How to Use Cross-Frame Communication
#### In the Parent Frame (LMS host)
```javascript
import CrossFrameLMS from 'scorm-again/cross-frame-lms';
import {Scorm12API} from 'scorm-again/scorm12';
const api = new Scorm12API({
autocommit: true,
logLevel: 1
});
// Create the server-side facade
// Allow messages from the child frame's origin
new CrossFrameLMS(api, 'https://child.example.com');
```
#### In the Child Frame (SCORM content)
```javascript
import CrossFrameAPI from 'scorm-again/cross-frame-api';
// Replace the global API with the cross-frame client
// Send messages to the parent LMS frame
window.API = window.API_1484_11 = new CrossFrameAPI('https://parent.example.com');
window.API.LMSInitialize();
window.API.LMSSetValue('cmi.core.lesson_status', 'completed');
window.API.LMSCommit();
```
### Notes
- No SharedArrayBuffer or Atomics; everything is async under the hood, but sync from the SCORM
module's perspective.
- Works in modern browsers. `CrossFrameAPI` needs `Proxy`, which IE11 lacks and which cannot be
polyfilled, so cross-frame mode does not work in IE11.
- For guaranteed Finish/Terminate delivery on unload, consider using `navigator.sendBeacon`.
## Offline Support
scorm-again provides robust offline capabilities that allow SCORM content to function without an
active internet connection. This is particularly valuable for mobile applications, remote areas with
limited connectivity, or scenarios with unreliable network conditions.
> **Note:** The Offline Support feature is currently being developed for scorm-again
> v3.0.0.
>
> I may consider splitting it out as a plugin to keep browser package size down.
### Key Features
- Run SCORM modules locally without network connectivity
- Automatically store SCORM data locally when offline
- Synchronize data back to the LMS when connectivity is restored
- Works seamlessly across multiple platforms and devices
### How to Enable Offline Support
```javascript
// Example configuration with offline support
const settings = {
// Standard settings
lmsCommitUrl: "https://your-lms.com/api/scorm/commit",
autocommit: true,
// Offline support settings
enableOfflineSupport: true, // Enable offline support
courseId: "COURSE-12345", // Unique identifier for the course
syncOnInitialize: true, // Attempt to sync data when initializing API
syncOnTerminate: true, // Attempt to sync data when terminating API
maxSyncAttempts: 5 // Maximum number of attempts to sync an item
};
// Create the API with offline support
const api = new Scorm12API(settings);
```
### Mobile Framework Integration
scorm-again provides detailed implementation examples for various mobile frameworks:
- React Native
- Flutter
- iOS (Native)
- Android (Native)
- Xamarin/MAUI
- Kotlin Multiplatform
For detailed implementation guides and examples, see
our [offline support documentation](https://jcputney.github.io/scorm-again/docs/advanced/offline-support).
## Documentation
### LMS Integration Documentation
- **[Player Wrapper Integration Guide](https://jcputney.github.io/scorm-again/docs/lms-integration/player-wrapper-guide)** - Build custom SCORM player UIs
- Event-driven UI updates
- SCORM 1.2, 2004 simple, and sequenced player implementations
- React, Vue, and Angular integration examples
- Event to UI mapping reference
- Troubleshooting guide
- **[LMS Integration Guide](https://jcputney.github.io/scorm-again/docs/lms-integration/integration-guide)** - Core LMS integration concepts
- [API Events Reference](https://jcputney.github.io/scorm-again/docs/lms-integration/api-events-reference) - Complete event system documentation
- [SCORM 1.2 Multi-SCO Guide](https://jcputney.github.io/scorm-again/docs/lms-integration/multi-sco-support) - Multi-SCO utilities
- [Cross-Frame Communication](https://jcputney.github.io/scorm-again/docs/lms-integration/cross-frame-communication) - Sandboxed iframe integration
### API Usage Documentation
- **API Examples**
- [SCORM 1.2 API Examples](docs/api_usage/examples/scorm12_examples.md)
- [SCORM 2004 API Examples](docs/api_usage/examples/scorm2004_examples.md)
- [Common Use Cases](docs/api_usage/use_cases/common_use_cases.md)
- [Troubleshooting Guide](docs/api_usage/troubleshooting/troubleshooting_guide.md)
### Developer Documentation
- [Development Workflow](https://jcputney.github.io/scorm-again/docs/developer/development-workflow)
- [Contribution Guidelines](https://jcputney.github.io/scorm-again/docs/developer/contributing)
- [Testing Strategy](https://jcputney.github.io/scorm-again/docs/developer/testing)
- [Method Standards](docs/method_standards.md)
### Bundle Size Optimization
To reduce the bundle size for production deployments:
1. **Use Production Builds**:
```bash
npm run build:prod
# or
npm run build:all:prod
```
This disables source maps unless NODE_ENV is set to 'production'.
2. **Use Minified Versions**:
Always use the `.min.js` versions in production for smaller file sizes.
3. **Import Specific APIs**:
Import only the specific API you need rather than the entire library:
```javascript
// Instead of
import {Scorm2004API} from 'scorm-again';
// Use
import {Scorm2004API} from 'scorm-again/scorm2004/min';
```
4. **Modern Browsers**:
If you don't need IE11 support, consider using the ESM versions for modern browsers:
```javascript
import {Scorm2004API} from 'scorm-again/scorm2004/min';
```
### Style Guide
- [TypeScript Style Guide](typescript_guidelines.md)
### Setup
To begin with, you include either the `scorm-again.js` or `scorm-again.min.js` file on your
launching page:
```html
<script type="text/javascript" src="/dist/scorm-again.js"></script>
```
Or, if you would like to only pull in one API, you include either the `scorm12.js` or
`scorm2004.js` files or their minified versions on your launching page:
```html
<script type="text/javascript" src="/dist/scorm2004.js"></script>
```
#### NPM/Yarn with ES Modules (ESM)
**Installing the package:**
```sh
npm install scorm-again
# or
yarn add scorm-again
```
#### CommonJS (Node.js or bundlers with CommonJS support)
**Importing the legacy build:**
```javascript
// Full library
const {Scorm12API, Scorm2004API} = require('scorm-again');
// Individual APIs
const {Scorm12API} = require('scorm-again/scorm12');
const {Scorm2004API} = require('scorm-again/scorm2004');
```
#### TypeScript Usage
TypeScript types are included with the package:
```typescript
import {Scorm12API, Scorm2004API} from 'scorm-again';
import {Settings} from 'scorm-again'; // Import types
// Create an instance with typed settings
const settings: Settings = {
autocommit: true,
logLevel: 'DEBUG'
};
const api = new Scorm2004API(settings);
```
#### Usage Examples
**Creating an API instance:**
```javascript
// Browser (after including the script)
const settings = {
autocommit: true,
lmsCommitUrl: 'https://your-lms.com/commit'
};
// SCORM 1.2
window.API = new Scorm12API(settings);
// SCORM 2004
window.API_1484_11 = new Scorm2004API(settings);
```
**Module usage with ES imports:**
```javascript
import {Scorm2004API} from 'scorm-again/scorm2004';
const settings = {
autocommit: true,
lmsCommitUrl: 'https://your-lms.com/commit'
};
// Create and attach to window for SCORM content to discover
window.API_1484_11 = new Scorm2004API(settings);
// Listen for events
window.API_1484_11.on('Initialize', () => {
console.log('SCORM API initialized');
});
```
### A Note About API Discovery
Before creating a ticket about your module not being able to communicate with the LMS, please make
sure you've looked
over my examples in the `gh-pages` branch, as well as reading
the [SCORM API Discovery Algorithms](https://scorm.com/scorm-explained/technical-scorm/run-time/api-discovery-algorithms/)
page. I get that some of this stuff can be hard to implement at first, but I can't give an example
for every possible
way this library can be loaded into your application. The main thing to remember is that it should
always be attached to
the `window` object, because that's where modules are supposed to look.
### Available Settings
The APIs include several settings to customize the functionality of each API:
| Setting | Default | Values | Description |
|----------------------------|:--------------------------------:|:-----------------------------------------------------------------------------------------------------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `autocommit` | false | true/false | Determines whether the API schedules an autocommit to the LMS after setting a value. |
| `autocommitSeconds` | 60 | int | Number of seconds to wait before autocommiting. Timer is restarted if another value is set. |
| `throttleCommits` | false | true/false | When enabled, throttles commit requests by delaying them 500ms, allowing rapid changes to be batched into a single commit. Only works when `useAsynchronousCommits=true`. Cannot be used with synchronous commits. |
| `useAsynchronousCommits` | false | true/false | Use async HTTP requests (legacy behavior). **Not SCORM compliant.** May cause data loss. Only use for specific legacy use cases. |
| `sendFullCommit` | true | true/false | Determines whether the API sends the full CMI object as part of the commit, or of it only sends the fields that actually contains values. |
| `lmsCommitUrl` | false | url | The URL endpoint of the LMS where data should be sent upon commit. If no value is provided, modules will run as usual, but all method calls will be logged to the console. |
| `dataCommitFormat` | `json` | `json`, `flattened`, `params` | `json` will send a JSON object to the lmsCommitUrl in the format of <br>`{'cmi': {'core': {...}}`<br><br> `flattened` will send the data in the format <br>`{'cmi.core.exit': 'suspend', 'cmi.core.mode': 'normal'...}`<br><br> `params` will send the data as <br>`?cmi.core.exit=suspend&cmi.core.mode=normal...` |
| `commitRequestDataType` | 'application/json;charset=UTF-8' | string | This setting is provided in case your LMS expects a different content type or character set. |
| `terminationCommitContentType` | 'text/plain;charset=UTF-8' | string | Content-Type used for sendBeacon commits. A non-CORS-safelisted value on a cross-origin commit URL may be silently dropped because Beacon cannot preflight; use fetch via `useAsynchronousCommits` with `asyncModeBeaconBehavior: "never"` for cross-origin JSON or custom auth headers. |
| `renderCommonCommitFields` | false |