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

Anyone have an idea how to use this with firebase functions? #5

Open
iamgoodbytes opened this issue Nov 30, 2018 · 4 comments
Open

Comments

@iamgoodbytes
Copy link

We could run this, but I'm not sure we should be using the request and response object or not? Thanks for any pointers!

exports.helloWorld = functions.https.onRequest((request, response) => {
    // response.send("Hello from Firebase!");
    app.use('/', proxy());
});
@urbantumbleweed
Copy link

+1

@urbantumbleweed
Copy link

urbantumbleweed commented May 1, 2019

This is my starting point.

const express = require('express');
const functions = require('firebase-functions');

const app = express();
app.use('/', proxy());

export default functions.https.onRequest(app);

I don't seem to be hitting the endpoint from the application. I am using config that is something like:

{
      useCORS: true,
      allowTaint: true,
      ignoreClasses: get(request, 'imageGeneration.ignoreClasses', []),
      ignoreElements: (element) => {
        const toIgnore = get(request, 'imageGeneration.ignoreClasses', []);
        const elementClasses = element.classList;
        const shouldIgnore = intersection(toIgnore, elementClasses);
        switch (true) {
          case shouldIgnore.length > 0:
            return true;
          default:
            return false;
        }
      },
      backgroundColor: null,
      width: get(request, 'pdfOptions.pageWidth', DEFAULT_CANVAS_PAGE_WIDTH),
      height: get(request, 'pdfOptions.pageHeight', DEFAULT_CANVAS_PAGE_HEIGHT),
      scale: 4.1666, // result of 300 dpi/ 72 dpi
      onclone: null,
      logging: false, // can be switched fon for debugging
      removeContainer: true,
      proxy: 'firebase-endpint-url/html2canvasProxy',
    };

Does anyone have thoughts?

@hanglooakshay
Copy link

This is my starting point.

const express = require('express');
const functions = require('firebase-functions');

const app = express();
app.use('/', proxy());

export default functions.https.onRequest(app);

I don't seem to be hitting the endpoint from the application. I am using config that is something like:

{
      useCORS: true,
      allowTaint: true,
      ignoreClasses: get(request, 'imageGeneration.ignoreClasses', []),
      ignoreElements: (element) => {
        const toIgnore = get(request, 'imageGeneration.ignoreClasses', []);
        const elementClasses = element.classList;
        const shouldIgnore = intersection(toIgnore, elementClasses);
        switch (true) {
          case shouldIgnore.length > 0:
            return true;
          default:
            return false;
        }
      },
      backgroundColor: null,
      width: get(request, 'pdfOptions.pageWidth', DEFAULT_CANVAS_PAGE_WIDTH),
      height: get(request, 'pdfOptions.pageHeight', DEFAULT_CANVAS_PAGE_HEIGHT),
      scale: 4.1666, // result of 300 dpi/ 72 dpi
      onclone: null,
      logging: false, // can be switched fon for debugging
      removeContainer: true,
      proxy: 'firebase-endpint-url/html2canvasProxy',
    };

Does anyone have thoughts?

Did you solve it though?

@Shafiyyah
Copy link

Shafiyyah commented Jul 30, 2024

Hi, I have tried using the library on firebase. Even though it has been 3 years since the last comment. Here is my working code:

Firebase Function Code:

const functions = require('firebase-functions');

const express = require('express'); // Rest API

var proxy = require('html2canvas-proxy');

var app = express();

app.use("/", proxy());

exports.app = functions.region('asia-east1').https.onRequest(app);

On the web code:

async Print () {
    let options= {
      allowTaint: false,
      useCORS: false,
      proxy: 'https://your function endpoint',
      logging: false
    }
    const table = document.getElementById("table");
    let filename = `${this.quotationID}_Quotation.png`
    await html2canvas(table, options).then(function(canvas) {
      var link = document.createElement('a');
      // console.log(this.quotationID)
      link.setAttribute('download', filename);
      link.href = canvas.toDataURL()
      link.click();
    });
  }

The documentation needs a bit of fixing on the web part. I just found out, from this fork https://github.com/zeusstl/html2canvas-proxy-nodejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants