Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: New activity control - load external script #12207

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mkomorski
Copy link
Collaborator

Type of change

  • Bugfix

  • Feature

  • New bidder adapter

  • Updated bidder adapter

  • Code style update (formatting, local variables)

  • Refactoring (no functional changes, no api changes)

  • Build related changes

  • CI related changes

  • Does this change affect user-facing APIs or examples documented on http://prebid.org?

  • Other

Description of change

Other information

#11010

src/adloader.js Outdated
@@ -50,6 +54,11 @@ const _approvedLoadExternalJSList = [
* @param {object} attributes an object of attributes to be added to the script with setAttribute by [key] and [value]; Only the attributes passed in the first request of a url will be added.
*/
export function loadExternalScript(url, moduleCode, callback, doc, attributes) {
if (!isActivityAllowed(LOAD_EXTERNAL_SCRIPT, activityParams(MODULE_TYPE_PREBID, 'adLoader'))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think to be useful the module should be the one attempting to load the script (rather than prebid/adloader). Otherwise I can only disable all scripts or none - the activity parameters are always the same. It does require some refactoring to get the caller's module type.

src/adloader.js Outdated
@@ -50,6 +54,11 @@ const _approvedLoadExternalJSList = [
* @param {object} attributes an object of attributes to be added to the script with setAttribute by [key] and [value]; Only the attributes passed in the first request of a url will be added.
*/
export function loadExternalScript(url, moduleCode, callback, doc, attributes) {
if (!isActivityAllowed(LOAD_EXTERNAL_SCRIPT, activityParams(MODULE_TYPE_PREBID, 'adLoader'))) {
logError('cannot load external script as it\'s disabled by activity controls');
Copy link
Collaborator

Choose a reason for hiding this comment

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

isActivityAllowed logs a warning when denied, so this is unnecessary IMO.

const unregisterRule = registerActivityControl(LOAD_EXTERNAL_SCRIPT, 'loadExternalScript config', () => ({allow: false}));
adLoader.loadExternalScript('someURL2', 'debugging');
expect(utilsLogErrorStub.called).to.be.true;
unregisterRule();
Copy link
Collaborator

@dgirardi dgirardi Sep 5, 2024

Choose a reason for hiding this comment

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

Test teardown is better done in a teardown hook (after/afterEach), or in a finally block. This is fine if the test passes, but if at some point some code change makes it fail, the teardown would not run and can potentially affect other tests, which makes it more difficult to find the failure.

@mkomorski mkomorski force-pushed the adloader-loadexternalscript branch 4 times, most recently from 5a613d9 to 13418b0 Compare September 11, 2024 09:12
@osazos
Copy link
Collaborator

osazos commented Sep 13, 2024

Hi,
The public documentation should be updated accordingly.

https://docs.prebid.org/dev-docs/activity-controls.html#activities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants