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

Revert "Implement Fallback for Blocked demdex.net Requests" #1214

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions src/core/edgeNetwork/injectSendEdgeNetworkRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import apiVersion from "../../constants/apiVersion.js";
import { createCallbackAggregator, noop } from "../../utils/index.js";
import mergeLifecycleResponses from "./mergeLifecycleResponses.js";
import handleRequestFailure from "./handleRequestFailure.js";
import { isNetworkError } from "../../utils/networkErrors.js";

const isDemdexBlockedError = (error, request) => {
return request.getUseIdThirdPartyDomain() && isNetworkError(error);
};

export default ({
config,
Expand All @@ -32,7 +27,6 @@ export default ({
getAssuranceValidationTokenParams,
}) => {
const { edgeDomain, edgeBasePath, datastreamId } = config;
let hasDemdexFailed = false;

/**
* Sends a network request that is aware of payload interfaces,
Expand All @@ -58,10 +52,9 @@ export default ({
onRequestFailure: onRequestFailureCallbackAggregator.add,
})
.then(() => {
const endpointDomain =
hasDemdexFailed || !request.getUseIdThirdPartyDomain()
? edgeDomain
: ID_THIRD_PARTY_DOMAIN;
const endpointDomain = request.getUseIdThirdPartyDomain()
? ID_THIRD_PARTY_DOMAIN
: edgeDomain;
const locationHint = getLocationHint();
const edgeBasePathWithLocationHint = locationHint
? `${edgeBasePath}/${locationHint}${request.getEdgeSubPath()}`
Expand Down Expand Up @@ -90,19 +83,7 @@ export default ({
processWarningsAndErrors(networkResponse);
return networkResponse;
})
.catch((error) => {
if (isDemdexBlockedError(error, request)) {
hasDemdexFailed = true;
request.setUseIdThirdPartyDomain(false);
return sendNetworkRequest({
requestId: request.getId(),
url: request.buildUrl(edgeDomain),
payload: request.getPayload(),
useSendBeacon: request.getUseSendBeacon(),
});
}
return handleRequestFailure(onRequestFailureCallbackAggregator)(error);
})
.catch(handleRequestFailure(onRequestFailureCallbackAggregator))
.then(({ parsedBody, getHeader }) => {
// Note that networkResponse.parsedBody may be undefined if it was a
// 204 No Content response. That's fine.
Expand Down
26 changes: 0 additions & 26 deletions src/utils/networkErrors.js

This file was deleted.

23 changes: 0 additions & 23 deletions test/functional/helpers/requestHooks/demdexBlockerMock.js

This file was deleted.

18 changes: 0 additions & 18 deletions test/functional/specs/Identity/C10922.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,9 @@ permutationsUsingDemdex.forEach((permutation) => {

if (areThirdPartyCookiesSupported()) {
await assertRequestWentToDemdex();

// Simulate demdex being blocked
networkLogger.edgeInteractEndpointLogs.requests = [];
const originalFetch = window.fetch;
window.fetch = (url) => {
if (url.includes("demdex.net")) {
return Promise.reject(new TypeError("Failed to fetch"));
}
return originalFetch(url);
};

await alloy.sendEvent();
// Should fallback to edge domain
await assertRequestDidNotGoToDemdex();

// Restore fetch
window.fetch = originalFetch;
} else {
await assertRequestDidNotGoToDemdex();
}

await networkLogger.clearLogs();
await reloadPage();
await alloy.configure(permutation.config);
Expand Down
40 changes: 0 additions & 40 deletions test/functional/specs/Identity/demdexFallback.js

This file was deleted.

82 changes: 50 additions & 32 deletions test/unit/specs/utils/dom/awaitSelector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,60 @@ governing permissions and limitations under the License.
*/

import awaitSelector from "../../../../../src/utils/dom/awaitSelector.js";
import selectNodes from "../../../../../src/utils/dom/selectNodes.js";
import {
createNode,
appendNode,
removeNode,
} from "../../../../../src/utils/dom/index.js";

describe("awaitSelector", () => {
it("await via requestAnimationFrame", (done) => {
// Create test element
const testElement = document.createElement("div");
testElement.id = "def";

// Immediately append element to document
document.body.appendChild(testElement);

// Now wait for selector
awaitSelector("#def")
.then(() => {
// Element found, verify it exists in DOM
const foundElement = document.querySelector("#def");
expect(foundElement).toBeTruthy();
expect(foundElement.id).toBe("def");

// Cleanup
document.body.removeChild(testElement);
done();
describe("DOM::awaitSelector", () => {
const createAndAppendNodeDelayed = (id) => {
setTimeout(() => {
appendNode(document.head, createNode("div", { id }));
}, 50);
};

const cleanUp = (id) => {
const nodes = selectNodes(`#${id}`);

removeNode(nodes[0]);
};

const awaitSelectorAndAssert = (id, win, doc) => {
const result = awaitSelector(`#${id}`, selectNodes, 1000, win, doc);

createAndAppendNodeDelayed(id);

return result
.then((nodes) => {
expect(nodes[0].tagName).toEqual("DIV");
})
.finally(() => {
cleanUp(id);
})
.catch((error) => {
// Cleanup on error
if (testElement.parentNode) {
document.body.removeChild(testElement);
}
done.fail(error);
.catch((e) => {
throw new Error(`${id} should be found. Error was ${e}`);
});
};

it("await via MutationObserver", () => {
return awaitSelectorAndAssert("abc", window, document);
});

// Ensure cleanup after all tests
afterAll(() => {
const element = document.querySelector("#def");
if (element) {
element.parentNode.removeChild(element);
}
it("await via requestAnimationFrame", () => {
const win = {
requestAnimationFrame: window.requestAnimationFrame.bind(window),
};
const doc = { visibilityState: "visible" };

return awaitSelectorAndAssert("def", win, doc);
});

it("await via timer", () => {
const win = {};
const doc = {};

return awaitSelectorAndAssert("ghi", win, doc);
});
});
48 changes: 0 additions & 48 deletions test/unit/specs/utils/networkErrors.spec.js

This file was deleted.

Loading