RDKEMW-23773 : Ad Request Failure on Linear CDAI and CDVR TS CDAI - #142
Conversation
There was a problem hiding this comment.
Pull request overview
Adds runtime support needed for ad/SDK code that relies on browser-like window.location and dynamic JSONP-style script loading in the JSDOM/MiniJSDOM execution path.
Changes:
- Replaces the inline
window.locationinjection with a helper that derives common location fields (protocol/host/path/query/hash/origin). - Ensures
windowandnavigatorare available onglobalin the linked JSDOM wrapper. - Implements a script-tag
appendChildhook that fetches external scriptsrccontent and executes it to enable JSONP-like flows.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/NativeJSRenderer.cpp | Adds setLocation() helper and uses it to inject a fuller window.location before running app code. |
| src/jsc/modules/linkedjsdomwrapper.js | Exposes window/navigator globally and adds a script appendChild hook to load/execute remote scripts. |
| include/NativeJSRenderer.h | Declares the new setLocation() helper. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (4)
Previously missed (1) — in code that hasn't changed since the last review.
src/NativeJSRenderer.cpp:754
linkedjsdomwrapper.jssetsdocument.location = window.locationonce during initialization, butrunApplicationInternal()later overwriteswindow.locationvia injected script. That leavesdocument.locationpointing at the stale object, and the URL change detection logic prefersdocument.location.hrefwhen it differs fromwindow.location.href, which can hide the updated URL. Updatedocument.locationalongsidewindow.locationin the injected script.
window << "window.location={"
<< "\"href\":\"" << url << "\","
<< "\"protocol\":\"" << protocol << "\","
<< "\"host\":\"" << host << "\","
<< "\"hostname\":\"" << hostname << "\","
<< "\"port\":\"" << port << "\","
<< "\"pathname\":\"" << pathname << "\","
<< "\"search\":\"" << search << "\","
<< "\"hash\":\"" << hash << "\","
<< "\"origin\":\"" << origin << "\""
<< "};";
}
src/NativeJSRenderer.cpp:386
- Building
localUrlas"file://" + urlproducesfile:////...whenurlis an absolute path (starts with/). This results in a non-canonical file URL and can confuse the URL parsing insetLocation(host becomes empty and pathname starts with//).
std::stringstream window;
std::string localUrl = "file://" + url;
setLocation(window, localUrl);
NativeJSLogger::log(INFO, "Adding the window location: %s to js file\n", window.str().c_str());
src/NativeJSRenderer.cpp:753
setLocation()directly interpolates URL components into JavaScript string literals without escaping. Ifurl(or derived parts) contains\,", or control characters, the injected script becomes invalid JS (or can be used for injection ifurlis externally supplied via the server API). Escape strings for JavaScript/JSON before writing them intowindow << ....
window << "window.location={"
<< "\"href\":\"" << url << "\","
<< "\"protocol\":\"" << protocol << "\","
<< "\"host\":\"" << host << "\","
<< "\"hostname\":\"" << hostname << "\","
<< "\"port\":\"" << port << "\","
<< "\"pathname\":\"" << pathname << "\","
<< "\"search\":\"" << search << "\","
<< "\"hash\":\"" << hash << "\","
<< "\"origin\":\"" << origin << "\""
src/NativeJSRenderer.cpp:725
setLocation()produces a non-browser-likepathnamefor URLs with no explicit path (e.g.,http://example.comyields an empty pathname, whereas browsers return/). Also, usingstd::minhere relies on<algorithm>being included somewhere else. Consider defaultingpathnameto/whenpathStartisnposand avoidstd::minto remove the header dependency.
if (pathStart != std::string::npos)
{
auto queryPos = url.find('?', pathStart);
auto hashPos = url.find('#', pathStart);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (5)
Previously missed (1) — in code that hasn't changed since the last review.
src/NativeJSRenderer.cpp:754
linkedjsdomwrapper.jssetsdocument.location = window.locationonce during initialization. Since this code replaceswindow.locationwith a new object,document.locationcan become stale. Keeping them in sync avoids diverging values for code that readsdocument.location.href.
<< "\"origin\":\"" << origin << "\""
<< "};";
src/NativeJSRenderer.cpp:742
- For hierarchical URLs like
http://example.com(no explicit path) orhttp://example.com?x=1,pathnameends up empty. Browsers defaultlocation.pathnameto "/" in these cases, and some clients rely on that.
if (protocol != "file:")
origin = protocol + "//" + host;
}
src/NativeJSRenderer.cpp:728
std::minis used here but the file does not include<algorithm>, which can cause build failures on toolchains that don't pull it in transitively. Either include<algorithm>or avoidstd::minhere.
auto pathEnd = std::min(
queryPos == std::string::npos ? url.size() : queryPos,
hashPos == std::string::npos ? url.size() : hashPos);
include/NativeJSRenderer.h:141
setLocationis only used as an internal helper in this translation unit (no external callers found). Keeping it public unnecessarily expands the class's public API surface.
std::string getBaseUserAgent();
void setLocation(std::stringstream& window, const std::string& url);
private:
include/NativeJSRenderer.h:140
- This header now exposes
std::stringstreamin the class interface but does not include<sstream>. The header may fail to compile when included from a TU that doesn't already include<sstream>.
void setLocation(std::stringstream& window, const std::string& url);
Reason for change: Added support for JSONP and window.location Test Procedure: Ads should play during Linear Channel Risk: low Priority: P2
eea0150 to
cb8aef3
Compare
Reason for change: Added support for JSONP and window.location
Test Procedure: Ads should play during Linear Channel
Risk: low
Priority: P2