Skip to content

refactor: streamline BetterBugs script loading in index.html#41639

Closed
sebastianiv21 wants to merge 1 commit intoreleasefrom
chore/update-betterbugs-html-script
Closed

refactor: streamline BetterBugs script loading in index.html#41639
sebastianiv21 wants to merge 1 commit intoreleasefrom
chore/update-betterbugs-html-script

Conversation

@sebastianiv21
Copy link
Copy Markdown
Contributor

@sebastianiv21 sebastianiv21 commented Mar 20, 2026

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Replaced the previous script loading method for BetterBugs with a more efficient inline function that checks for recording status before appending the necessary scripts. This change enhances performance by conditionally loading scripts only when required, improving the overall user experience.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/23329064176
Commit: 5d8b25b
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Fri, 20 Mar 2026 05:08:12 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Bug Fixes

  • Improved BetterBugs recording functionality to intelligently manage support script loading. Recording scripts now load only when no active session is detected, preventing conflicts and reducing unnecessary resource consumption during active recording operations.

Replaced the previous script loading method for BetterBugs with a more efficient inline function that checks for recording status before appending the necessary scripts. This change enhances performance by conditionally loading scripts only when required, improving the overall user experience.
@sebastianiv21 sebastianiv21 requested a review from tomjose92 March 20, 2026 04:27
@sebastianiv21 sebastianiv21 added the ok-to-test Required label for CI label Mar 20, 2026
@sebastianiv21
Copy link
Copy Markdown
Contributor Author

/build-deploy-preview skip-tests=true

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

Walkthrough

The BetterBugs script loader in index.html is refactored to conditionally inject external scripts only when no active recording is detected via URL parameters and localStorage state, switching from append to prepend insertion.

Changes

Cohort / File(s) Summary
BetterBugs Conditional Loader
app/client/public/index.html
Adds conditional logic to skip injecting logs-capture.js and recorder.js when the URL contains betterbugs-recording or when localStorage.recordingStatuses indicates an active recording. Script insertion method changed from appendChild() to prepend().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Scripts that dance with caution wise,
Check the localStorage's replies—
Skip the load when recording's near,
Prepend instead of append dear. 🎬✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description lacks critical details: no specific issue reference, unclear recording status logic, and missing context about the functional changes. Replace placeholder 'Fixes #Issue Number' with an actual issue link, clarify whether scripts load when recording is active or inactive, and provide motivation for the conditional loading change.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: streamlining BetterBugs script loading by making it conditional based on recording status, which aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/update-betterbugs-html-script
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/23329077839.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 41639.
recreate: .
base-image-tag: .

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/client/public/index.html`:
- Line 84: The dynamic loader currently uses o(n) to create async scripts and
document.head.prepend, which reverses required order and sets async=true; modify
the loader so that logs-capture.js is inserted before recorder.js and not marked
async: change o(n) to append scripts via document.head.appendChild (or create
the first script for "https://cdn.betterbugs.io/scripts/latest/logs-capture.js"
and attach an onload handler that then creates and appends the recorder script),
and remove r.async = true so scripts load and execute in sequence; update code
paths that call n() and o() accordingly to ensure "logs-capture.js" always loads
and finishes before "recorder.js".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 677a22dd-0047-4aa0-80d0-2ff175483cf3

📥 Commits

Reviewing files that changed from the base of the PR and between f46326c and 5d8b25b.

📒 Files selected for processing (1)
  • app/client/public/index.html

s2.async = true;
document.head.appendChild(s2);
})();
!function(){function n(){var r=new URLSearchParams(window.location.search);if(r.has("betterbugs-recording"))return!0;try{var e=localStorage.getItem("recordingStatuses");if(e){var t=JSON.parse(e);if(Array.isArray(t)&&t.some(function(n){return n&&!0===n.currentlyRecording}))return!0}}catch(n){}return!1}function o(n){var r=document.createElement("script");r.src=n,r.async=!0,document.head.prepend(r)}n()&&(o("https://cdn.betterbugs.io/scripts/latest/logs-capture.js"),o("https://cdn.betterbugs.io/scripts/latest/recorder.js"))}();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Does BetterBugs recording-link integration document whether logs-capture.jsandrecorder.jscan be injected in any order, and whether dynamically loading both scripts withasync=true is supported?

💡 Result:

No, the BetterBugs recording-link integration documentation does not explicitly state whether logs-capture.js and recorder.js can be injected in any order, nor does it document support for dynamically loading both scripts with async=true. The official documentation (primarily at https://docs.betterbugs.io/dashboard/workspace-settings/recording-links) instructs to add both scripts sequentially to the HTML tag without async attributes: <script src="https://cdn.betterbugs.io/scripts/latest/logs-capture.js"></script> <script src="https://cdn.betterbugs.io/scripts/latest/recorder.js"></script> This implies logs-capture.js loads first, followed by recorder.js. No mention is made of order flexibility, async/defer attributes, or dynamic injection (e.g., via JavaScript document.createElement('script') with async=true). Examples consistently show this static, blocking order in . No troubleshooting, configuration options, or GitHub source code addresses dependencies or async loading compatibility.

Citations:


Fix the BetterBugs script loading order and async strategy.

BetterBugs documentation explicitly requires logs-capture.js to load before recorder.js, as synchronous blocking scripts. Using prepend() reverses this critical order, and async=true is not documented as supported for dynamic injection. Use appendChild() instead of prepend(), or chain the second script to the first's onload handler to maintain proper sequencing and loading behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/client/public/index.html` at line 84, The dynamic loader currently uses
o(n) to create async scripts and document.head.prepend, which reverses required
order and sets async=true; modify the loader so that logs-capture.js is inserted
before recorder.js and not marked async: change o(n) to append scripts via
document.head.appendChild (or create the first script for
"https://cdn.betterbugs.io/scripts/latest/logs-capture.js" and attach an onload
handler that then creates and appends the recorder script), and remove r.async =
true so scripts load and execute in sequence; update code paths that call n()
and o() accordingly to ensure "logs-capture.js" always loads and finishes before
"recorder.js".

@github-actions
Copy link
Copy Markdown

Deploy-Preview-URL: https://ce-41639.dp.appsmith.com

@github-actions
Copy link
Copy Markdown

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions Bot added the Stale label Mar 27, 2026
@sebastianiv21 sebastianiv21 deleted the chore/update-betterbugs-html-script branch March 27, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant