Class: Puppeteer::DOMWorld::BindingFunction
- Inherits:
- 
      Object
      
        - Object
- Puppeteer::DOMWorld::BindingFunction
 
- Defined in:
- lib/puppeteer/dom_world.rb
Instance Attribute Summary collapse
- 
  
    
      #name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute name. 
Instance Method Summary collapse
- #call(*args) ⇒ Object
- 
  
    
      #initialize(name:, proc:)  ⇒ BindingFunction 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of BindingFunction. 
- #page_binding_init_string ⇒ Object
Constructor Details
#initialize(name:, proc:) ⇒ BindingFunction
Returns a new instance of BindingFunction.
| 8 9 10 11 | # File 'lib/puppeteer/dom_world.rb', line 8 def initialize(name:, proc:) @name = name @proc = proc end | 
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
| 17 18 19 | # File 'lib/puppeteer/dom_world.rb', line 17 def name @name end | 
Instance Method Details
#call(*args) ⇒ Object
| 13 14 15 | # File 'lib/puppeteer/dom_world.rb', line 13 def call(*args) @proc.call(*args) end | 
#page_binding_init_string ⇒ Object
| 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # File 'lib/puppeteer/dom_world.rb', line 19 def page_binding_init_string <<~JAVASCRIPT (type, bindingName) => { /* Cast window to any here as we're about to add properties to it * via win[bindingName] which TypeScript doesn't like. */ const win = window; const binding = win[bindingName]; win[bindingName] = (...args) => { const me = window[bindingName]; let callbacks = me.callbacks; if (!callbacks) { callbacks = new Map(); me.callbacks = callbacks; } const seq = (me.lastSeq || 0) + 1; me.lastSeq = seq; const promise = new Promise((resolve, reject) => callbacks.set(seq, { resolve, reject }) ); binding(JSON.stringify({ type, name: bindingName, seq, args })); return promise; }; } JAVASCRIPT end |