title: Getting "A JavaScript exception occurred" When evaluateJavaScript on WKWebView in Objective-C
body: <p>Here I am using Reference swift project to load a PDF file in PDFViewer in WKWebview.</p>
  
  <p>Reference Project - <a href="https://github.com/Minitex/PDFJSTest/blob/master/PDFJSTest/ViewController.swift" rel="nofollow noreferrer">https://github.com/Minitex/PDFJSTest/blob/master/PDFJSTest/ViewController.swift</a></p>
  
  <p>Here in the reference project have a code look like this for load PDF file </p>
  
  <pre><code>func openPDFInViewer(myURL: URL)
  {
      let pdf = NSData(contentsOf: myURL)
  
      let length = pdf?.length
      var myArray = [UInt8](repeating: 0, count: length!)
      pdf?.getBytes(&amp;myArray, length: length!)
  
      webView?.evaluateJavaScript("PDFViewerApplication.open(new Uint8Array(\(myArray)))", completionHandler: { result, error in
          print("Completed Javascript evaluation.")
          print("Result: \(String(describing: result))")
          print("Error: \(String(describing: error))")
     })
  }
  </code></pre>
  
  <p>And I tried to convert this function into Objective-C language and it looks like this:</p>
  
  <pre><code>-(void)renderPDF:(NSTimer*)theTimer
  {
      NSMutableDictionary *dictData = [[NSMutableDictionary alloc] initWithDictionary:theTimer.userInfo];
      NSURL *requestURL =  (NSURL *)[dictData valueForKey:@"request_url"];
  
      NSData *data = [NSData dataWithContentsOfURL:requestURL];
      NSUInteger len = [data length];
      uint8_t myArray[len];
      [data getBytes:&amp;myArray length:len];
  
      NSString *strForEvaluate = [NSString stringWithFormat:@"PDFViewerApplication.open(new Uint8Array('%s'));",myArray];
  
  
      [wkWebView evaluateJavaScript:strForEvaluate completionHandler:^(id Result, NSError * _Nullable error) {
          if (error)
          {
              NSLog(@"This is error....%@",error.description);
          }
          else if(Result)
          {
              NSLog(@"%@",Result);
          }
       }];
  }
  </code></pre>
  
  <p>When I tried to run the app and evaluateJavaScript function that time getting error response like this</p>
  
  <pre><code>Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=SyntaxError: Unexpected EOF, WKJavaScriptExceptionColumnNumber=0, WKJavaScriptExceptionSourceURL=file:///Users/sapanaranipa/Library/Developer/CoreSimulator/Devices/207FA841-3256-45D2-8698-2B769A72A2F4/data/Containers/Bundle/Application/4BD7E620-DF16-429B-BBC2-2A36BA2A2DE8/SureFox.app//PDF_Web/pdf.js-dist/web/viewer.html, NSLocalizedDescription=A JavaScript exception occurred}
  </code></pre>
  
  <p>Please help me, Thanks in Advance.</p>