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

Exempt Safari and WebKit-based DDG browsers from using serverTiming #206

Merged
merged 1 commit into from
May 15, 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
6 changes: 3 additions & 3 deletions adClickFlow/ad/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ console.log('Ad conversion');

const pixelUrl = new URL('./ping.gif', document.currentScript.src);

function fireResource (status) {
function fireConvertPingStatus (status) {
window.dispatchEvent(new CustomEvent('resourceLoad', {
detail: {
url: pixelUrl.href,
Expand All @@ -16,9 +16,9 @@ img.src = pixelUrl;
img.style.display = 'none';
img.onload = () => {
console.log('Ad conversion complete');
fireResource('loaded');
fireConvertPingStatus('loaded');
};
img.onerror = () => {
fireResource('blocked');
fireConvertPingStatus('blocked');
};
document.body.appendChild(img);
7 changes: 4 additions & 3 deletions adClickFlow/ad/track.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
console.log('Tracking');

const trackingImgUrl = new URL('./ping.gif', document.currentScript.src);
function fireResource (status) {

function fireTrackingPingStatus (status) {
window.dispatchEvent(new CustomEvent('resourceLoad', {
detail: {
url: trackingImgUrl.href,
Expand All @@ -14,9 +15,9 @@ const trackingImg = document.createElement('img');
trackingImg.src = trackingImgUrl;
trackingImg.style.display = 'none';
trackingImg.onload = () => {
fireResource('loaded');
fireTrackingPingStatus('loaded');
};
trackingImg.onerror = () => {
fireResource('blocked');
fireTrackingPingStatus('blocked');
};
document.body.appendChild(trackingImg);
8 changes: 6 additions & 2 deletions adClickFlow/shared/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function getAdHostname (hostname) {
return isLocalTest ? 'ad-company.example' : 'ad-company.site';
}

function isSafariOrDDG() {
return navigator.vendor && navigator.vendor.indexOf('Apple') > -1;
}

function getAdUrl (id, hostname) {
// Build Ad Redirection URL
const adHostname = getAdHostname(hostname);
Expand Down Expand Up @@ -341,8 +345,8 @@ export class FinishObserver {
this.observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
entries.map((entry) => {
// Safari doesn't support serverTiming nor does it fire events for blocked loads either.
if (entry.serverTiming) {
// WebKit doesn't seem to support serverTiming for cross-origin loads
if (entry.serverTiming && !isSafariOrDDG()) {
if (entry.serverTiming.length === 0) {
this.setResourceStatus(entry.name, 'blocked');
} else {
Expand Down
Loading