Skip to content

Commit

Permalink
Revert "Implement Fallback for Blocked demdex.net Requests (#1210)"
Browse files Browse the repository at this point in the history
This reverts commit e6d4f5a.
  • Loading branch information
shammowla authored Nov 8, 2024
1 parent b4f4e78 commit e4331e6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 210 deletions.
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.

0 comments on commit e4331e6

Please sign in to comment.