Skip to content

NaN values in nav index #82

@virtualarchitectures

Description

@virtualarchitectures

Hi, I'm working on my own fork of Zeeschuimer and identified that some values for nav_index are returned with NaN values "nav_index":"6:26:NaN. I thought I'd raise it here as a potential issue in case it has implications for your integration with 4CAT.

Full disclosure: I investigated the issue using Claude Code (response below). If this is expected behaviour or if you are unhappy with use of Claude code in the analysis, feel free to close this issue.

In zs-background.js:222, nav_handler is missing .first() on the Dexie query:
// BUG: db.nav.where(...) returns a WhereClause object, not a record
let nav = await db.nav.where({"session": this.session, "tab_id": tabId});

Since a WhereClause object is always truthy, the if (!nav) guard never fires. Then nav["index"] is undefined, and undefined + 1 = NaN.
That NaN gets written to the DB and read back by parse_request when building the string session:tab_id:NaN.

This only triggers on actual page navigations (when the webNavigation.onCommitted event fires). The first captured batch uses index: 0 (set by parse_request correctly), then navigation increments it to NaN.

Contrast with parse_request at line 157, which correctly uses .first():
let nav_index = await db.nav.where({"tab_id": tabId, "session": this.session}).first();

Proposed Fix is a one-line change in js\zs-background.js for nav_handler:

 222 -        let nav = await db.nav.where({"session": this.session, "tab_id": tabId}); // Replace this
 222 +       let nav = await db.nav.where({"session": this.session, "tab_id": tabId}).first(); // With this
 223          if (!nav) {
 224              nav = {"session": this.session, "tab_id": tabId, "index": 0}
 225              await db.nav.add(nav);

Note: Row numbers may differ.

I hope that's useful. I'm not fully clear if this is a problem for the 4CAT integration or not. If not, feel free to ignore and close.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions