refactor: route _fs_namespace reads through getFsNamespace helper#250
Open
pablofullstory wants to merge 1 commit into
Open
refactor: route _fs_namespace reads through getFsNamespace helper#250pablofullstory wants to merge 1 commit into
pablofullstory wants to merge 1 commit into
Conversation
| /** | ||
| * Resolves the FullStory client namespace on `window`. | ||
| * | ||
| * Mirrors the resolution order used by `@fullstory/browser-api`: |
Contributor
There was a problem hiding this comment.
let's say fs.js instead of @fullstory/browser-api since that's an internal package and this is theoretically an open source repo.
ScottLNorvell
approved these changes
May 29, 2026
Contributor
ScottLNorvell
left a comment
There was a problem hiding this comment.
LGTM! Just the one comment about removing the reference to @fullstory/browser-api. (which I'm sure that silly LLM put there hahhaha)
| }); | ||
|
|
||
| it('prefers the script attribute over _fs_namespace when both are present', () => { | ||
| const win = makeWin({ scriptAttr: 'AttrWins', fsNamespace: 'GlobalLoses' }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
DLO had four hard-coded
window._fs_namespacereads, which silently break forsites whose FullStory snippet uses a custom namespace (set via the
data-fs-namespacescript attribute) without also setting the_fs_namespaceglobal. This PR centralizes the lookup behind a single helper that mirrors the
resolution order used by
@fullstory/browser-api.src/utils/fsNamespace.tsexportinggetFsNamespace(win = window):data-fs-namespaceondocument.currentScript→_fs_namespaceglobal →'FS'.Self-contained (no
@fullstory/browser-apidependency); defensivetry/catcharound
documentaccess; empty-string attribute falls through to the global.src/utils/logger.ts—FullStoryAppender.logsrc/operators/fsApi/fsApi.ts—FSApiOperator.handleData(also tightens the throw message to
Fullstory namespace is not a function)src/target.ts—DataLayerTargetconstructor's "is this the FS object?" guardsrc/embed/init.impl.ts—attachDloFullStoryLifecycleBehavior
_fs_namespaceglobal still work — thehelper falls back to the global, which is the same floor the old code had.
data-fs-namespace="MyFS"on the FullStory snippet but do notset
_fs_namespacenow resolve correctly (this was the bug).document.currentScriptis only meaningful while a script tag is beingevaluated synchronously. DLO calls the helper from deferred callbacks
(appender log, operator
handleData, lifecycle hook), so the attribute pathis opportunistic; the global remains the practical fallback. This matches how
@fullstory/browser-api's owngetFsNamespaceis shaped.Test plan
npm test— 428 passing, including 8 new cases intest/fs-namespace.spec.tscovering: attribute wins over global, empty-string attribute is ignored,
missing/null
currentScriptfalls through, errors during document accessare swallowed, default
'FS'floor, andundefinedwindow.npm run lint— clean (only pre-existingno-consolewarnings remain).npm run build— clean.window._fs_namespace = 'FS'(logger.spec.ts,lifecycle-embed.spec.ts,operator-fsApi.spec.ts) still pass via thehelper's global fallback.
Note
Low Risk
Localized integration refactor with preserved global/
FSfallbacks and new unit tests; no auth or data-path changes.Overview
Introduces
getFsNamespaceso every FullStory client lookup uses the same resolution order as@fullstory/browser-api:data-fs-namespaceondocument.currentScript(when available), then_fs_namespace, then'FS'. Document access is wrapped intry/catch; an empty script attribute is ignored.Replaces four direct
window._fs_namespacereads inFullStoryAppender,FSApiOperator,DataLayerTarget, andattachDloFullStoryLifecyclewith the helper. Sites that only set the global behave as before; sites that set a custom namespace on the snippet but omit_fs_namespaceshould now resolve the correct client function.Adds
test/fs-namespace.spec.tsfor precedence, deferred/nullcurrentScript, errors, and the default floor.Reviewed by Cursor Bugbot for commit 3bb3717. Bugbot is set up for automated code reviews on this repo. Configure here.