@@ -55,44 +55,47 @@ export function renderCrossDomain(win, adId, pubAdServerDomain = '', pubUrl) {
55
55
}
56
56
57
57
if ( adObject . message && adObject . message === 'Prebid Response' &&
58
- adObject . adId === adId &&
59
- ( adObject . ad || adObject . adUrl ) ) {
60
- let body = win . document . body ;
61
- let ad = adObject . ad ;
62
- let url = adObject . adUrl ;
63
- let width = adObject . width ;
64
- let height = adObject . height ;
58
+ adObject . adId === adId ) {
59
+ try {
60
+ let body = win . document . body ;
61
+ let ad = adObject . ad ;
62
+ let url = adObject . adUrl ;
63
+ let width = adObject . width ;
64
+ let height = adObject . height ;
65
65
66
- if ( adObject . mediaType === 'video' ) {
67
- signalRenderResult ( false , {
68
- reason : 'preventWritingOnMainDocument' ,
69
- message : `Cannot render video ad ${ adId } `
70
- } ) ;
71
- console . log ( 'Error trying to write ad.' ) ;
72
- } else if ( ad ) {
73
- const iframe = getEmptyIframe ( adObject . height , adObject . width ) ;
74
- body . appendChild ( iframe ) ;
75
- iframe . contentDocument . open ( ) ;
76
- iframe . contentDocument . write ( ad ) ;
77
- iframe . contentDocument . close ( ) ;
78
- signalRenderResult ( true ) ;
79
- } else if ( url ) {
80
- const iframe = getEmptyIframe ( height , width ) ;
81
- iframe . style . display = 'inline' ;
82
- iframe . style . overflow = 'hidden' ;
83
- iframe . src = url ;
66
+ if ( adObject . mediaType === 'video' ) {
67
+ signalRenderResult ( false , {
68
+ reason : 'preventWritingOnMainDocument' ,
69
+ message : `Cannot render video ad ${ adId } `
70
+ } ) ;
71
+ console . log ( 'Error trying to write ad.' ) ;
72
+ } else if ( ad ) {
73
+ const iframe = getEmptyIframe ( adObject . height , adObject . width ) ;
74
+ body . appendChild ( iframe ) ;
75
+ iframe . contentDocument . open ( ) ;
76
+ iframe . contentDocument . write ( ad ) ;
77
+ iframe . contentDocument . close ( ) ;
78
+ signalRenderResult ( true ) ;
79
+ } else if ( url ) {
80
+ const iframe = getEmptyIframe ( height , width ) ;
81
+ iframe . style . display = 'inline' ;
82
+ iframe . style . overflow = 'hidden' ;
83
+ iframe . src = url ;
84
84
85
- insertElement ( iframe , document , 'body' ) ;
86
- signalRenderResult ( true ) ;
87
- } else {
88
- signalRenderResult ( false , {
89
- reason : 'noAd' ,
90
- message : `No ad for ${ adId } `
91
- } ) ;
92
- console . log ( `Error trying to write ad. No ad for bid response id: ${ id } ` ) ;
85
+ insertElement ( iframe , document , 'body' ) ;
86
+ signalRenderResult ( true ) ;
87
+ } else {
88
+ signalRenderResult ( false , {
89
+ reason : 'noAd' ,
90
+ message : `No ad for ${ adId } `
91
+ } ) ;
92
+ console . log ( `Error trying to write ad. No ad markup or adUrl for ${ adId } ` ) ;
93
+ }
94
+ } catch ( e ) {
95
+ signalRenderResult ( false , { reason : "exception" , message : e . message } ) ;
96
+ console . log ( `Error in rendering ad` , e ) ;
93
97
}
94
98
}
95
- }
96
99
97
100
function signalRenderResult ( success , { reason, message } = { } ) {
98
101
const payload = {
0 commit comments