# Browser.GetElementById()\` throws exception when called from \`\[Export\]\` class method

**URL:** https://talk.remobjects.com/t/browser-getelementbyid-throws-exception-when-called-from-export-class-method/33960
**Category:** Oxygene
**Tags:** island, wasm
**Created:** [September 11, 2026, 4:03am UTC](https://talk.remobjects.com/t/browser-getelementbyid-throws-exception-when-called-from-export-class-method/33960 "2026-09-11T04:03:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ianjblakeley](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/i/f9ae1b/32.png) [@ianjblakeley](https://talk.remobjects.com/u/ianjblakeley)
#### Post date: [September 11, 2026, 4:03am UTC](https://talk.remobjects.com/t/browser-getelementbyid-throws-exception-when-called-from-export-class-method/33960/1 "2026-09-11T04:03:28Z")

</div>

Description

`Browser.GetElementById()` from `RemObjects.Elements.WebAssembly.DOM` throws an exception (silently caught, not propagated to JavaScript console) when called from a method in an `[Export]`ed class.

The same API call works perfectly when called from:

- Non-exported classes
- Methods called later in the application lifecycle (e.g., from view classes)

### Minimal Reproduction

```auto
namespace BugRepro;

uses
  RemObjects.Elements.WebAssembly.DOM;

type
  [Export]
  App = public class
  public
    method Start;
    begin
      // This line throws an exception (silently):
      var el := Browser.GetElementById('app-root');

      // This is never reached:
      if el <> nil then begin
        var dwin: dynamic := (el as HTMLElement).ownerDocument.defaultView;
        dwin.console.log('[WASM] SUCCESS');
      end;
    end;
  end;

end.

```

```auto
<!DOCTYPE html>
<html>
<body>
  <div id="app-root"></div>
  <script src="RemObjectsElements.js"></script>
  <script src="BugRepro.js"></script>
  <script>
    BugRepro.instantiate("BugRepro.wasm").then(function(result) {
      console.log('[JS] Creating App...');
      var app = result.App();
      console.log('[JS] App created');
      console.log('[JS] Calling Start()...');
      app.Start();
      console.log('[JS] Start() returned');
      // BUG: No '[WASM] SUCCESS' message appears in console
    });
  </script>
</body>
</html>

```

### Expected Behavior

`Browser.GetElementById('app-root')` should return the HTMLElement and `[WASM] SUCCESS` should be logged to console.

### Actual Behavior

- `app.Start()` returns immediately
- No console output from WASM code
- No JavaScript exception thrown
- The exception is silently caught within WASM runtime

### Workaround

Call `Browser.GetElementById()` from **non-exported** helper methods or from methods invoked later (not directly from the exported class’s entry point).

### Additional Notes

- Other methods in the same codebase successfully use `Browser.GetElementById()` without issues
- The timing appears related - calling it from `Start()` immediately after WASM instantiation fails
- Adding `[DisableInlining]` attribute did not help
- Using `try/except` in Oxygene does not catch the exception

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [September 17, 2026, 1:54pm UTC](https://talk.remobjects.com/t/browser-getelementbyid-throws-exception-when-called-from-export-class-method/33960/2 "2026-09-17T13:54:56Z")

</div>

bugs://E27881

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [September 17, 2026, 2:27pm UTC](https://talk.remobjects.com/t/browser-getelementbyid-throws-exception-when-called-from-export-class-method/33960/3 "2026-09-17T14:27:25Z")

</div>

Afraid we cannot reproduce this one here:

> [@](#):
>
> The posted example does not fail here. In Chromium 152 with the local compiler and WebAssembly 1.1 SDK:
> 
> - Original class and HTML: success, with WASM exceptions both off and on.
> - Immediate, helper, and delayed calls: all succeed.
> - Missing element: returns nil normally.
> 
> Removing `app-root` reproduces the reported **quiet return with no success log** , without an exception. That is a possible explanation, not an established cause—the posted HTML contains the element.
> 
> To narrow this further, we’d need the actual failing project or generated JS/WASM and the exact compiler/SDK versions. `[Export]` plus an immediate call alone does not reproduce it.
