Running the following code in the QGIS Python console clips all features in the currently active layer with a polygon that exactly covers the current viewport, and adds the clipped features to a memory layer:
viewportPolygon = QgsGeometry().fromWkt(iface.mapCanvas().extent().asWktPolygon())
layer = iface.activeLayer()
resultlayer = QgsVectorLayer("Polygon", "result", "memory")
resultlayer.dataProvider().addAttributes(list(layer.dataProvider().fields()))
clippedFeatures = []
for feature in layer.dataProvider().getFeatures():
clippedGeometry = feature.geometry().intersection(viewportPolygon)
if not clippedGeometry.isGeosEmpty():
feature.setGeometry(clippedGeometry)
clippedFeatures.append(feature)
resultlayer.dataProvider().addFeatures(clippedFeatures)
QgsMapLayerRegistry.instance().addMapLayer(resultlayer)