diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d85a75e..be7f90f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,45 +4,8 @@ on: [push, pull_request] env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCS_PATH: ${{ secrets.DOCS_PATH }} - DOCS_BRANCH: ${{ secrets.DOCS_BRANCH }} jobs: - can_document: - runs-on: ubuntu-latest - outputs: - value: ${{ steps.check_job.outputs.value }} - steps: - - name: Checks whether documentation can be built - id: check_job - run: | - echo "value: ${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}" - echo "value=${{ env.DOCS_PATH != null && github.ref == env.DOCS_BRANCH }}" >> "$GITHUB_OUTPUT" - - documentation: - needs: [can_document] - runs-on: ubuntu-latest - if: needs.can_document.outputs.value == 'true' - - steps: - - uses: actions/checkout@v7 - - - name: Use Node.js - uses: actions/setup-node@v7 - with: - node-version: "20.x" - registry-url: 'https://registry.npmjs.org' - - - name: Install Dependencies - run: | - cd $DOCS_PATH - npm install - - - name: Deploy Doclet - run: | - cd $DOCS_PATH - npx pilet publish --fresh --url https://feed.piral.cloud/api/v1/pilet/anglesharp --api-key ${{ secrets.PIRAL_FEED_KEY }} - linux: runs-on: ubuntu-latest @@ -55,7 +18,7 @@ jobs: 10.0.x - name: Build - run: ./build.sh -AngleSharpVersion 1.10.0 + run: ./build.sh -AngleSharpVersion 1.11.0 windows: runs-on: windows-latest @@ -85,9 +48,9 @@ jobs: NUGET_API_KEY: ${{ steps.nuget_login.outputs.NUGET_API_KEY }} run: | if ($env:GITHUB_REF -eq "refs/heads/main") { - .\build.ps1 -Target Publish -AngleSharpVersion 1.10.0 + .\build.ps1 -Target Publish -AngleSharpVersion 1.11.0 } elseif ($env:GITHUB_REF -eq "refs/heads/devel") { - .\build.ps1 -Target PrePublish -AngleSharpVersion 1.10.0 + .\build.ps1 -Target PrePublish -AngleSharpVersion 1.11.0 } else { - .\build.ps1 -AngleSharpVersion 1.10.0 + .\build.ps1 -AngleSharpVersion 1.11.0 } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f0a2821..f975dd09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +# 1.3.0 + +Released on Tuesday, November 24 2026. + +- Fixed a module with a top-level `await` blocking the page for many seconds +- Fixed import map entries of a prefix not being used +- Fixed an `import()` of a module that could not be fetched not rejecting with a `TypeError` +- Fixed the DOM of libraries registered by a creator only being missing +- Fixed an object getting the prototype of an unrelated class of another library +- Updated a WebIDL namespace to be a plain object, whose members are no longer members of the window too +- Updated minimum version of AngleSharp to 1.11.0 +- Added `WithJs(DomRegistration)` to register the DOM of libraries declared for a scripting engine (#152) +- Added `SharedWorker`, which the scripts of an origin creating it for the same address +- Added CSS module scripts (`import sheet from './a.css' with { type: 'css' }`), whose default export is a constructed style sheet +- Added `import.meta.resolve()` +- Added interfaces of a namespace (`[DomExposed("WebAssembly")]` puts `WebAssembly.Module` there instead of on the window) +- Added delegates of the DOM as functions of scripts +- Added `BigInteger` as BigInt, `Memory` as an ArrayBuffer +- Added exceptions of the DOM (e.g. `WebAssembly.RuntimeError`) being errors of their class +- Added the Web Cryptography API (`crypto.subtle`, also in workers; not on .NET Framework) + # 1.2.3 Released on Sunday, November 22 2026. diff --git a/docs/README.md b/docs/README.md index 29d9695b..4552d353 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,3 +3,6 @@ We have more detailed information regarding the following subjects: - [Getting Started](general/01-Basics.md) +- [API Documentation](tutorials/01-API.md) +- [Examples](tutorials/02-Examples.md) +- [Frequently Asked Questions](tutorials/03-Questions.md) diff --git a/docs/general/01-Basics.md b/docs/general/01-Basics.md index 99931621..953c33a2 100644 --- a/docs/general/01-Basics.md +++ b/docs/general/01-Basics.md @@ -4,11 +4,7 @@ section: "AngleSharp.Js" --- # Getting Started -AngleSharp.Js runs JavaScript against an AngleSharp document. It integrates the -[Jint](https://github.com/sebastienros/jint) interpreter with AngleSharp, so scripts can -read and change the same DOM that your .NET code uses. This is useful when processing pages -whose behavior depends on script execution, evaluating a snippet in a document context, or -hosting JavaScript APIs alongside your application. +AngleSharp.Js runs JavaScript against an AngleSharp document. It integrates the [Jint](https://github.com/sebastienros/jint) interpreter with AngleSharp, so scripts can read and change the same DOM that your .NET code uses. This is useful when processing pages whose behavior depends on script execution, evaluating a snippet in a document context, or hosting JavaScript APIs alongside your application. ## Install and configure @@ -18,13 +14,9 @@ Install the package: Install-Package AngleSharp.Js ``` -Add `WithJs()` to the AngleSharp configuration. Add `WithEventLoop()` when scripts, events, -or resource callbacks must run in the browser-like task queue. Add a loader when the document -needs to fetch external scripts or other resources. +Add `WithJs()` to the AngleSharp configuration. Add `WithEventLoop()` when scripts, events, or resource callbacks must run in the browser-like task queue. Add a loader when the document needs to fetch external scripts or other resources. -For many real-world scripts, `WithJs()` alone is not enough. AngleSharp.Js exposes interfaces -from the AngleSharp services present in the browsing context, so you usually want to include -AngleSharp.Io and AngleSharp.Css to provide most of the required API surface. +For many real-world scripts, `WithJs()` alone is not enough. AngleSharp.Js exposes interfaces from the AngleSharp services present in the browsing context, so you usually want to include AngleSharp.Io and AngleSharp.Css to provide most of the required API surface. ```cs var configuration = Configuration.Default @@ -42,12 +34,9 @@ var document = await context.OpenAsync("https://example.com"); await document.WaitUntilAvailable(); ``` -Some highly specialized scripts may also depend on additional AngleSharp packages. For example, -in niche scenarios, libraries such as AngleSharp.Wasm can be relevant. +Some highly specialized scripts may also depend on additional AngleSharp packages. For example, in niche scenarios, libraries such as AngleSharp.Wasm can be relevant. -`WithJs()` registers the JavaScript scripting service, support for inline event attributes -such as `onclick`, a navigation handler for `javascript:` URLs, and a default `navigator` -when the configuration does not already provide one. +`WithJs()` registers the JavaScript scripting service, support for inline event attributes such as `onclick`, a navigation handler for `javascript:` URLs, structured cloning (for `postMessage` and workers) and the host for custom elements. It does not register a loader, an event loop or a navigator; `WithNavigator()` from AngleSharp.Io provides a full `navigator`. ### Customize the event loop @@ -93,11 +82,21 @@ var configuration = Configuration.Default }); ``` +### Configure the Jint engine + +Register an `EngineCreator` to construct the Jint engine yourself, for example to limit the statements, time or memory a script may use. The delegate runs once per window and must build the engine from the supplied options: + +```cs +var configuration = Configuration.Default + .With(new EngineCreator((window, options) => new Jint.Engine(options + .MaxStatements(1_000_000) + .TimeoutInterval(TimeSpan.FromSeconds(5))))) + .WithJs(); +``` + ## Execute JavaScript -HTML `")) + .WaitUntilAvailable(); + +var output = document.GetElementById("out").TextContent; // "2,4,6" +``` + +## Interact with the page: click, then inspect + +Events dispatched from .NET reach JavaScript listeners, and the other way round. + +```cs +var config = Configuration.Default.WithJs().WithEventLoop(); +var document = await BrowsingContext.New(config).OpenAsync(req => req.Content(@" + 0 + ")) + .WaitUntilAvailable(); + +var button = (IHtmlElement)document.GetElementById("btn"); // AngleSharp.Html.Dom +button.DoClick(); +button.DoClick(); + +await document.WhenStable(); +var clicks = document.GetElementById("n").TextContent; // "2" +``` + +Inline handlers such as `