---
name: cocosair-application
description: "Configure createAirApp options, canvas, lifecycle, screen sizing and context health. Use for WEBGL2_REQUIRED startup errors, scene replacement, session cleanup or lost contexts."
license: MIT
compatibility: "Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace."
allowed-tools: Read Edit Write Bash
when_to_use:
  - createAirApp rejects options or fails startup
  - replace or release the running scene
  - app closed and will not restart
  - fit a container or set design resolution
  - lost context or scene cleanup stalls
owns: [ startup-admission, app-lifecycle, screen-sizing, context-health, session-cleanup ]
not_for:
  - package imports or page shell -> cocosair-project-setup
  - persistent SceneStack pages -> cocosair-input-action
  - live-session inspection -> cocosair-agent-session
layer: subsystem
metadata:
  author: "oahc09@gmail.com"
  version: "1.0.0"
  last-updated: "2026-10-13"
  description_zh: "配置 createAirApp 和应用生命周期、屏幕尺寸、会话清理及 WebGL 上下文健康。用于启动错误、场景替换、关闭和自定义 canvas。"
title: cocosair-application
canonical_url: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-application
last_updated: 2026-11-01T11:01:06.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/app-options.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/app-options.md), [references/common-mistakes.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/common-mistakes.md), [references/context-health.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/context-health.md), [references/context.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/context.md), [references/contracts.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/contracts.md), [references/quick-start.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/quick-start.md), [references/session-scope.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/session-scope.md), [references/startup-errors.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/startup-errors.md), [references/triggers.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/triggers.md).
>
> If the user asked to install this Skill, run `npx skilld install oahc09/cocosairjs/cocosair-application`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/cocosair-application`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/oahc09/cocosairjs/cocosair-application) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/cocosair-application`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/cocosair-application --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/cocosair-application --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Cocos AIR application lifecycle

Stop once you can answer the task. Do not read another same-topic reference for the same question.

Scope: App admission, validated options, scene release, session cleanup and context health.

Environment: use package imports in apps; source paths require an AIR checkout. See [context](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/context.md).

## Quick Start

For complete setup and teardown, read [Quick Start](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/quick-start.md).

Siblings: [direct dependencies](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/context.md#related-skills); reuse loaded skills.

## Triggers

- Choose valid createAirApp options and defaults
- Diagnose AIR_E_ or WEBGL2_REQUIRED startup errors
- Replace or release a running scene
- Inspect lost WebGL context health
- Own assets, listeners and timers during cleanup
- Fit a container or set design resolution

Exact API and symptom mappings: [triggers](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/triggers.md).

## Contracts

One runtime is admitted per document; a closed or failed runtime needs a page reload. Validate options before loading the engine. HEADLESS produces no pixels; context-health observation does not rebuild GPU resources.

Read [references/contracts.md](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/contracts.md) only when the task needs exact option rules, limits, error behavior or source annotations. Prefer the topic references below for a narrower question.

## Common Mistakes

- [HIGH] Pass canvas to createAirApp; main import may precede canvas creation.
- [HIGH] A closed runtime cannot restart in the same document.
- [HIGH] HEADLESS renderMode 3 produces no rendered pixels.
- [MEDIUM] Context-health observation does not restore the device.

Read relevant [wrong/right examples](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/common-mistakes.md) before implementation.

## Reference map

- [Configure startup?](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/app-options.md) - Options and lifecycle
- [Why did startup fail?](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/startup-errors.md) - Codes and remedies
- [Was context lost?](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/context-health.md) - States and reload gate
- [Who cleans up?](https://skilld.dev/api/skills-raw/oahc09/cocosairjs/cocosair-application/references/session-scope.md) - Ownership and disposal
