Skip to content

Commit

Permalink
ps: Test for feature support (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapo authored Apr 2, 2024
1 parent bc1f838 commit 3809ac4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/addons/paapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ OptableSDK.prototype.installGPTAuctionConfigs = function (filter?: GPTSlotFilter
* runAdAuction runs an ad auction locally for a given spot dom ID.
*/
OptableSDK.prototype.runAdAuction = async function (domID: string): Promise<boolean> {
const supported = "runAdAuction" in navigator;
if (!supported) {
throw "run-ad-auction not supported";
}

const spot = document.getElementById(domID);
if (!spot) {
throw "spot not found";
Expand Down Expand Up @@ -127,6 +132,11 @@ OptableSDK.prototype.runAdAuction = async function (domID: string): Promise<bool
* joinAdInterestGroups injects an iframe into the page that tags the device into the matching audiences interest group.
*/
OptableSDK.prototype.joinAdInterestGroups = async function () {
const supported = "joinAdInterestGroup" in navigator;
if (!supported) {
throw "join-ad-interest-group not supported";
}

const siteConfig = await this.site();
if (!siteConfig.interestGroupPixel) {
throw "origin not enabled for protected audience apis";
Expand Down
5 changes: 5 additions & 0 deletions lib/addons/topics-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ declare module "../sdk" {
* getTopics injects an iframe into the page that obtains the browsingTopics observed by optable.
*/
OptableSDK.prototype.getTopics = async function (): Promise<BrowsingTopic[]> {
const supported = "browsingTopics" in document;
if (!supported) {
throw "browsing-topics not supported";
}

const siteConfig = await this.site();
if (!siteConfig.getTopicsURL) {
throw "origin not enabled for topics api";
Expand Down

0 comments on commit 3809ac4

Please sign in to comment.